summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Hernandez <jhernandez@soleta.eu>2024-02-07 10:34:25 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-02-09 13:21:55 +0100
commit6ec26d161e148d7e428ace954fb19b9edb5d4b67 (patch)
tree2d2e95f702d1e92233cb05642d0fef910ce16231
parenta609ede7a8ff94921f703ee395e3be3426a6da2d (diff)
views: add update center
add view to update center data such as its name or comment.
-rw-r--r--ogcp/forms/action_forms.py1
-rw-r--r--ogcp/templates/scopes.html2
-rw-r--r--ogcp/views.py46
3 files changed, 49 insertions, 0 deletions
diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py
index 525f45b..2fd9326 100644
--- a/ogcp/forms/action_forms.py
+++ b/ogcp/forms/action_forms.py
@@ -168,6 +168,7 @@ class ImageUpdateForm(FlaskForm):
class CenterForm(FlaskForm):
server = SelectField(label=_l('Server'),
validators=[InputRequired()])
+ center = HiddenField()
name = StringField(label=_l('Center name'),
validators=[InputRequired()])
comment = StringField(label=_l('Comment'))
diff --git a/ogcp/templates/scopes.html b/ogcp/templates/scopes.html
index 40d6f75..0dde6a6 100644
--- a/ogcp/templates/scopes.html
+++ b/ogcp/templates/scopes.html
@@ -54,6 +54,8 @@
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<input class="btn btn-light dropdown-item {% block nav_center_add %}{% endblock %}" type="submit" value="{{ _('Add center') }}"
form="scopesForm" formaction="{{ url_for('action_center_add') }}" formmethod="get">
+ <input class="btn btn-light dropdown-item {% block nav_center_update %}{% endblock %}" type="submit" value="{{ _('Update center') }}"
+ form="scopesForm" formaction="{{ url_for('action_center_update') }}" formmethod="get">
<input class="btn btn-light dropdown-item {% block nav_center_delete %}{% endblock %}" type="submit" value="{{ _('Delete center') }}"
form="scopesForm" formaction="{{ url_for('action_center_delete') }}" formmethod="get">
</div>
diff --git a/ogcp/views.py b/ogcp/views.py
index 2929f8f..2dbe342 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -1897,6 +1897,52 @@ def action_center_add():
return render_template('actions/add_center.html', form=form,
scopes=scopes)
+@app.route('/action/center/update', methods=['GET', 'POST'])
+@login_required
+def action_center_update():
+ form = CenterForm(request.form)
+ if request.method == 'POST':
+ payload = {"id": int(form.center.data),
+ "name": form.name.data,
+ "comment": form.comment.data}
+ server = get_server_from_ip_port(form.server.data)
+ r = server.post('/center/update', payload)
+ if r.status_code != requests.codes.ok:
+ flash(_('Server replied with error code when updating the center'),
+ category='error')
+ else:
+ flash(_('Center updated successfully'), category='info')
+ return redirect(url_for("scopes"))
+ else:
+ params = request.args.to_dict()
+ server = params.get('scope-server')
+ center = params.get('scope-center')
+ if not server:
+ flash(_('Internal error: server was not sent as request argument'),
+ category='error')
+ return redirect(url_for("scopes"))
+ if not center:
+ flash(_('Please, select one center'), 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
+
+ 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.name.data = r.json()['name']
+
+ scopes, clients = get_scopes()
+ form.submit.render_kw = {"formaction": url_for('action_center_update')}
+ return render_template('actions/center_update.html', form=form,
+ scopes=scopes)
+
def get_scope_context_rec(elem_id, elem_type, scopes, ancestors):
if not scopes:
return ([], None)