From d135a4806dc12d24240fd50fcbcb5ab6f5c89db1 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Mon, 17 Jun 2024 16:42:09 +0200 Subject: ogcp: add center details view to scopes management Add a readonly view for the center data. Mark all the form fields as readonly and set the hidden attribute to the submit field. --- ogcp/templates/actions/center_details.html | 18 +++++++++++++++ ogcp/templates/scopes.html | 2 ++ ogcp/views.py | 36 ++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 ogcp/templates/actions/center_details.html diff --git a/ogcp/templates/actions/center_details.html b/ogcp/templates/actions/center_details.html new file mode 100644 index 0000000..5f5d37a --- /dev/null +++ b/ogcp/templates/actions/center_details.html @@ -0,0 +1,18 @@ +{% extends 'scopes.html' %} +{% import "bootstrap/wtf.html" as wtf %} + +{% set sidebar_state = 'disabled' %} +{% set btn_back = true %} + +{% block nav_center %} active {% endblock %} +{% block nav_center_details %} active {% endblock %} +{% block content %} + +

{{_('Center details')}}

+ +{{ wtf.quick_form(form, + method='post', + button_map={'submit': 'primary'}, + extra_classes="mx-5") }} + +{% endblock %} diff --git a/ogcp/templates/scopes.html b/ogcp/templates/scopes.html index a96ae62..04285be 100644 --- a/ogcp/templates/scopes.html +++ b/ogcp/templates/scopes.html @@ -60,6 +60,8 @@ form="scopesForm" formaction="{{ url_for('action_center_update') }}" formmethod="get"> + diff --git a/ogcp/views.py b/ogcp/views.py index 886ff13..9e1a028 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -2219,6 +2219,42 @@ def action_center_update(): return render_template('actions/center_update.html', form=form, scopes=scopes) +@app.route('/action/center/info', methods=['GET']) +@login_required +def action_center_info(): + form = CenterForm(request.form) + params = request.args.to_dict() + server = params.get('scope-server') + center = params.get('scope-center') + if not center: + flash(_('Please, select one center'), category='error') + return redirect(url_for("scopes")) + if not server: + flash(_('Internal error: server was not sent as request argument'), + category='error') + return redirect(url_for("scopes")) + + server = get_server_from_ip_port(server) + + form.server.choices = [(server.ip + ':' + str(server.port), server.name)] + form.server.render_kw = {'readonly': True} + form.center.data = center + form.center.render_kw = {'readonly': True} + + payload = {"id": int(center)} + r = server.get('/center/info', payload) + if r.status_code != requests.codes.ok: + return ogserver_error('scopes') + form.comment.data = r.json()['comment'] + form.comment.render_kw = {'readonly': True} + form.name.data = r.json()['name'] + form.name.render_kw = {'readonly': True} + form.submit.render_kw = {'readonly': True, 'hidden': True} + + scopes, clients = get_scopes() + return render_template('actions/center_details.html', form=form, + scopes=scopes) + def get_scope_context_rec(elem_id, elem_type, scopes, ancestors): if not scopes: return ([], None) -- cgit v1.2.3-18-g5258