diff options
author | Javier Sánchez Parra <jsanchez@soleta.eu> | 2021-05-11 15:21:11 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2021-05-20 18:45:34 +0200 |
commit | 29480012e40f85e61568021776d660a9f73b7ea3 (patch) | |
tree | c9e1a2d5bbf4b6ddbf7a1ccc63cec6e8d7f3eda8 /ogcp/views.py | |
parent | f303240c554fde68ded5aff4a13f96d07508eb7d (diff) |
Add "Delete Room" form and view
Creates "delete room" form with a select to choose a room to delete.
Adds a new button inside the button group in the scopes view. Because
scopes checkboxes values maps to ips the only way to specify the room to
delete is in the delete room form itself, using a select input.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index 73b1fcb..794400d 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -3,7 +3,8 @@ from flask import ( ) from ogcp.forms.action_forms import ( WOLForm, PartitionForm, ClientDetailsForm, HardwareForm, SessionForm, - ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm, RoomForm + ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm, RoomForm, + DeleteRoomForm ) from flask_login import ( current_user, LoginManager, @@ -90,6 +91,8 @@ def parse_scopes_from_tree(tree, scope_type): scopes = [] for scope in tree['scope']: if scope['type'] == scope_type: + if 'name' in tree: + scope['parent'] = tree['name'] scopes.append(scope) else: scopes += parse_scopes_from_tree(scope, scope_type) @@ -674,3 +677,24 @@ def action_room_add(): centers = [(center['id'], center['name']) for center in centers] form.center.choices = list(centers) return render_template('actions/add_room.html', form=form) + +@app.route('/action/room/delete', methods=['GET', 'POST']) +@login_required +def action_room_delete(): + form = DeleteRoomForm(request.form) + if request.method == 'POST': + payload = {"id": form.room.data} + r = g.server.post('/room/delete', payload) + if r.status_code != requests.codes.ok: + flash(_('Server replied with error code when deleting the room'), + category='error') + else: + flash(_('Room deleted successfully'), category='info') + return redirect(url_for("scopes")) + else: + r = g.server.get('/scopes') + rooms = parse_scopes_from_tree(r.json(), 'room') + rooms = [(room['id'], room['name'] + " (" + room['parent'] + ")") + for room in rooms] + form.room.choices = list(rooms) + return render_template('actions/delete_room.html', form=form) |