From a609ede7a8ff94921f703ee395e3be3426a6da2d Mon Sep 17 00:00:00 2001 From: Javier Hernandez Date: Tue, 6 Feb 2024 12:14:14 +0100 Subject: views: Add update room Add view to modify room information such as name, gateway and netmask --- ogcp/forms/action_forms.py | 1 + ogcp/templates/actions/room_update.html | 19 ++++++++++++++ ogcp/templates/scopes.html | 2 ++ ogcp/views.py | 44 +++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 ogcp/templates/actions/room_update.html diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index 8586665..525f45b 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -180,6 +180,7 @@ class DeleteCenterForm(FlaskForm): class RoomForm(FlaskForm): server = HiddenField() + room = HiddenField() center = SelectField(label=_l('Center'), validators=[InputRequired()]) name = StringField(label=_l('Room name'), diff --git a/ogcp/templates/actions/room_update.html b/ogcp/templates/actions/room_update.html new file mode 100644 index 0000000..608b904 --- /dev/null +++ b/ogcp/templates/actions/room_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_room %} active{% endblock %} +{% block nav_room_add %} active{% endblock %} +{% block content %} + +

{{_('Update room')}}

+ +{{ 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 6d3ab4b..40d6f75 100644 --- a/ogcp/templates/scopes.html +++ b/ogcp/templates/scopes.html @@ -41,6 +41,8 @@ diff --git a/ogcp/views.py b/ogcp/views.py index d667e26..2929f8f 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -2008,6 +2008,50 @@ def action_room_add(): return render_template('actions/add_room.html', form=form, scopes=scopes) +@app.route('/action/room/update', methods=['GET', 'POST']) +@login_required +def action_room_update(): + form = RoomForm(request.form) + if request.method == 'POST': + server = get_server_from_ip_port(form.server.data) + payload = {"name": form.name.data, + "netmask": form.netmask.data, + "gateway": form.gateway.data, + "id": int(form.room.data)} + r = server.post('/room/update', payload) + if r.status_code != requests.codes.ok: + flash(_('Server replied with error code when updating the room'), category='error') + else: + flash(_('Room updated successfully'), category='info') + return redirect(url_for("scopes")) + else: + params = request.args.to_dict() + room_id = params.get('scope-room') + if not room_id: + flash(_('Please, select a room to update'), category='error') + return redirect(url_for('scopes')) + server = get_server_from_ip_port(params['scope-server']) + + del form.center + form.server.data = params['scope-server'] + form.room.data = room_id + + payload = {"id": int(room_id)} + r = server.get('/room/info', payload) + if not r: + return ogserver_down('scopes') + if r.status_code != requests.codes.ok: + return ogserver_error('scopes') + form.name.data = r.json()['name'] + form.gateway.data = r.json()['gateway'] + form.netmask.data = r.json()['netmask'] + + form.submit.render_kw = {"formaction": url_for('action_room_update')} + + scopes, clients = get_scopes() + return render_template('actions/room_update.html', form=form, + scopes=scopes) + @app.route('/action/room/delete', methods=['GET', 'POST']) @login_required def action_room_delete(): -- cgit v1.2.3-18-g5258