From d9537005768d6bad3b6ccdc07678217d3be9b9c3 Mon Sep 17 00:00:00 2001 From: Javier Hernandez Date: Mon, 5 Feb 2024 13:11:25 +0100 Subject: views: Add edit-folder Add view to modify folder information such as name --- ogcp/templates/actions/folder_update.html | 19 ++++++++++++++++ ogcp/templates/scopes.html | 2 ++ ogcp/views.py | 36 +++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 ogcp/templates/actions/folder_update.html diff --git a/ogcp/templates/actions/folder_update.html b/ogcp/templates/actions/folder_update.html new file mode 100644 index 0000000..51985e4 --- /dev/null +++ b/ogcp/templates/actions/folder_update.html @@ -0,0 +1,19 @@ +{% extends 'scopes.html' %} +{% import "bootstrap/wtf.html" as wtf %} + +{% set sidebar_state = 'disabled' %} +{% set btn_back = true %} + +{% block nav_folder %} active{% endblock %} +{% block nav_folder_update %} active{% endblock %} +{% block content %} + +

{{_('Update folder')}}

+ +{{ 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 23b3d3c..6d3ab4b 100644 --- a/ogcp/templates/scopes.html +++ b/ogcp/templates/scopes.html @@ -64,6 +64,8 @@ diff --git a/ogcp/views.py b/ogcp/views.py index 9321660..d667e26 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -1229,6 +1229,38 @@ def action_folder_delete(): return render_template('actions/folder_delete.html', form=form, parent="scopes.html", scopes=scopes, ancestors=ancestors, children=children) +@app.route('/action/folder/update', methods=['GET','POST']) +def action_folder_update(): + form = FolderForm(request.form) + if request.method == 'POST': + payload = {'name': form.name.data, + 'id': int(form.folder_id.data)} + + server = get_server_from_ip_port(form.server.data) + r = server.post('/folder/update', payload) + if r.status_code != requests.codes.ok: + flash(_('ogServer: error updating folder'), + category='error') + else: + flash(_('Folder updated successfully'), category='info') + return redirect(url_for("scopes")) + else: + params = request.args.to_dict() + folder_id = int(params.get('folder')) + + if not folder_id: + flash(_('Please, select a folder to modify'), category='error') + return redirect(url_for('scopes')) + + scopes, clients = get_scopes() + folder = find_element_scope(folder_id, 'folder', scopes) + form.server.data = params['scope-server'] + form.name.data = folder['name'] + form.folder_id.data = folder_id + form.submit.render_kw = {"formaction": url_for('action_folder_update')} + return render_template('actions/folder_update.html', form=form, + parent="scopes.html", scopes=scopes) + @app.route('/action/folder/add', methods=['GET']) @login_required def action_folder_add(): @@ -1884,6 +1916,10 @@ def get_scope_context_rec(elem_id, elem_type, scopes, ancestors): else: return ([], None) +def find_element_scope(elem_id, elem_type, scopes): + unused, elem = get_scope_context_rec(elem_id, elem_type, scopes['scope'], []) + return elem + def get_scope_context(elem_id, elem_type, scopes): ancestors, elem = get_scope_context_rec(elem_id, elem_type, scopes['scope'], []) children = {} -- cgit v1.2.3-18-g5258