diff options
Diffstat (limited to 'ogcp')
-rw-r--r-- | ogcp/forms/action_forms.py | 5 | ||||
-rw-r--r-- | ogcp/templates/actions/delete_room.html | 15 | ||||
-rw-r--r-- | ogcp/templates/scopes.html | 2 | ||||
-rw-r--r-- | ogcp/views.py | 26 |
4 files changed, 47 insertions, 1 deletions
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 %} + +<h1 class="m-5">{{_('Delete room form')}}</h1> + +{{ 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"> <input class="dropdown-item" type="submit" value="{{ _('Add room') }}" formaction="{{ url_for('action_room_add') }}" formmethod="get"> + <input class="dropdown-item" type="submit" value="{{ _('Delete room') }}" + formaction="{{ url_for('action_room_delete') }}" formmethod="get"> </div> </div> </form> 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) |