From edd44da64c4660a7b3eb195cdf11eae88d95c85a Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Wed, 4 Dec 2024 16:36:04 +0100 Subject: ogcp: add Lives category to the main navbar Add Lives view and show the lives installed in each server in the sidebar. Add view to set a new default live image in the Lives view. --- ogcp/forms/action_forms.py | 1 + ogcp/templates/actions/live_default.html | 21 ++++++++++++ ogcp/templates/base.html | 3 ++ ogcp/templates/lives.html | 57 ++++++++++++++++++++++++++++++++ ogcp/views.py | 57 +++++++++++++++++++++++++++++++- 5 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 ogcp/templates/actions/live_default.html create mode 100644 ogcp/templates/lives.html diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index acd63bd..4d5d52a 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -191,6 +191,7 @@ class BootModeForm(FlaskForm): class OgliveForm(FlaskForm): ips = HiddenField() + server = HiddenField() oglive = SelectField(label=_l('ogLive')) ok = SubmitField(label=_l('Submit')) diff --git a/ogcp/templates/actions/live_default.html b/ogcp/templates/actions/live_default.html new file mode 100644 index 0000000..5cd6858 --- /dev/null +++ b/ogcp/templates/actions/live_default.html @@ -0,0 +1,21 @@ +{% extends 'lives.html' %} +{% import "bootstrap/wtf.html" as wtf %} + +{% set sidebar_state = 'disabled' %} +{% set btn_back = true %} + +{% block content %} + +

+ {{ _('Set default ogLive') }} +

+ +

{{ _('Default live: %(default_live)s', default_live=default_live) }}

+ +{{ wtf.quick_form(form, + action=url_for('action_live_default'), + method='post', + button_map={'ok': 'primary'}, + extra_classes="m-5") }} + +{% endblock %} \ No newline at end of file diff --git a/ogcp/templates/base.html b/ogcp/templates/base.html index 2bdadfc..5efe462 100644 --- a/ogcp/templates/base.html +++ b/ogcp/templates/base.html @@ -43,6 +43,9 @@ + diff --git a/ogcp/templates/lives.html b/ogcp/templates/lives.html new file mode 100644 index 0000000..7aaf9c9 --- /dev/null +++ b/ogcp/templates/lives.html @@ -0,0 +1,57 @@ +{% extends 'base.html' %} + +{% block nav_lives %}active{% endblock %} + +{% block container %} +
+ +
+ {{ super() }} + + + +{% endblock %} + +{% block sidebar %} + +{% endblock %} + +{% block commands %} +{% if current_user.is_authenticated %} + + {% if btn_back %} + + {% endif %} +{% endif %} +{% endblock %} diff --git a/ogcp/views.py b/ogcp/views.py index 5d08f28..f298213 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -3484,7 +3484,6 @@ def action_repo_info(): def manage_servers(): return render_template('servers.html', servers=servers) - @app.route('/server/update', methods=['GET']) @login_required def server_update_get(): @@ -3638,6 +3637,62 @@ def server_delete_post(): category='error') return redirect(url_for('manage_servers')) +@app.route('/lives/', methods=['GET']) +@login_required +def manage_lives(): + oglive_list = multi_request('get', '/oglive/list') + return render_template('lives.html', oglive_list=oglive_list, servers=servers) + +@app.route('/action/live/default', methods=['GET', 'POST']) +@login_required +def action_live_default(): + form = OgliveForm(request.form) + if request.method == 'POST': + try: + server = get_server_from_ip_port(form.server.data) + except KeyError: + flash(_('Please, select one server'), category='error') + return redirect(url_for('manage_lives')) + payload = {'name': form.oglive.data} + r = server.post('/oglive/default', payload) + if not r: + return ogserver_down('manage_lives') + if r.status_code == requests.codes.ok: + flash(_('Set default ogLive request sent successfully'), + category='info') + else: + flash(_('Ogserver replied with status code not ok'), + category='error') + return redirect(url_for('manage_lives')) + else: + params = request.args.to_dict() + try: + server = get_server_from_ip_port(params['server']) + except KeyError: + flash(_('Please, select one server'), category='error') + return redirect(url_for('manage_lives')) + r = server.get('/oglive/list') + if not r: + return ogserver_down('commands') + if r.status_code != requests.codes.ok: + return ogserver_error('commands') + + oglive_list = r.json()['oglive'] + + available_oglives = [] + for oglive in oglive_list: + live_entry = (oglive.get('directory'), oglive.get('directory')) + available_oglives.append(live_entry) + + default_idx = int(r.json()['default']) + default_live = oglive_list[default_idx].get('directory') + + form.oglive.choices = available_oglives + form.server.data = params['server'] + form.ok.render_kw = {'formaction': url_for('action_live_default')} + + oglive_list = multi_request('get', '/oglive/list') + return render_template('actions/live_default.html', oglive_list=oglive_list, form=form, default_live=default_live) @app.route('/users/', methods=['GET']) @login_required -- cgit v1.2.3-18-g5258