summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorJavier Hernandez <jhernandez@soleta.eu>2024-02-06 12:14:14 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-02-09 13:17:29 +0100
commita609ede7a8ff94921f703ee395e3be3426a6da2d (patch)
tree155adfce2ab6892d4a5c56497dfaddc3859d100d /ogcp/views.py
parentd9537005768d6bad3b6ccdc07678217d3be9b9c3 (diff)
views: Add update room
Add view to modify room information such as name, gateway and netmask
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():