From 29480012e40f85e61568021776d660a9f73b7ea3 Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Tue, 11 May 2021 15:21:11 +0200 Subject: 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. --- ogcp/forms/action_forms.py | 5 +++++ ogcp/templates/actions/delete_room.html | 15 +++++++++++++++ ogcp/templates/scopes.html | 2 ++ ogcp/views.py | 26 +++++++++++++++++++++++++- 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 ogcp/templates/actions/delete_room.html (limited to 'ogcp') diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index 3bd3ef5..54b2c32 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -98,3 +98,8 @@ class RoomForm(FlaskForm): netmask = StringField(label=_('Netmask'), validators=[InputRequired()]) submit = SubmitField(label=_('Submit')) + +class DeleteRoomForm(FlaskForm): + room = SelectField(label=_('Room'), + validators=[InputRequired()]) + submit = SubmitField(label=_('Submit')) diff --git a/ogcp/templates/actions/delete_room.html b/ogcp/templates/actions/delete_room.html new file mode 100644 index 0000000..a5aa529 --- /dev/null +++ b/ogcp/templates/actions/delete_room.html @@ -0,0 +1,15 @@ +{% extends 'base.html' %} +{% import "bootstrap/wtf.html" as wtf %} + +{% block content %} + +

{{_('Delete room form')}}

+ +{{ wtf.quick_form(form, + action=url_for('action_room_delete'), + method='post', + button_map={'submit': 'primary'}, + extra_classes="mx-5") }} + +{% endblock %} + diff --git a/ogcp/templates/scopes.html b/ogcp/templates/scopes.html index df2b535..3cb84fd 100644 --- a/ogcp/templates/scopes.html +++ b/ogcp/templates/scopes.html @@ -61,6 +61,8 @@ formaction="{{ url_for('action_mode') }}" formmethod="get"> + 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) -- cgit v1.2.3-18-g5258