summaryrefslogtreecommitdiffstats
path: root/ogcp
diff options
context:
space:
mode:
Diffstat (limited to 'ogcp')
-rw-r--r--ogcp/forms/action_forms.py1
-rw-r--r--ogcp/templates/actions/room_update.html19
-rw-r--r--ogcp/templates/scopes.html2
-rw-r--r--ogcp/views.py44
4 files changed, 66 insertions, 0 deletions
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 %}
+
+<h1 class="m-5">{{_('Update room')}}</h1>
+
+{{ 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 @@
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<input class="btn btn-light dropdown-item {% block nav_room_add %}{% endblock %}" type="submit" value="{{ _('Add room') }}"
form="scopesForm" formaction="{{ url_for('action_room_add') }}" formmethod="get">
+ <input class="btn btn-light dropdown-item {% block nav_room_update %}{% endblock %}" type="submit" value="{{ _('Update room') }}"
+ form="scopesForm" formaction="{{ url_for('action_room_update') }}" formmethod="get">
<input class="btn btn-light dropdown-item {% block nav_room_delete %}{% endblock %}" type="submit" value="{{ _('Delete room') }}"
form="scopesForm" formaction="{{ url_for('action_room_delete') }}" formmethod="get">
</div>
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():