summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py44
1 files changed, 44 insertions, 0 deletions
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():