diff options
author | Javier Sánchez Parra <jsanchez@soleta.eu> | 2021-07-30 12:15:29 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2021-07-30 13:01:38 +0200 |
commit | 9d98cf0423e7fa0e74bc06ae8d47c9d4896564c1 (patch) | |
tree | d514d393c909e80dc2f50e9f521deff02d33c571 /ogcp/views.py | |
parent | 95c113f0674bda60cce7f1cc82ec1bf2777ed170 (diff) |
Add "Delete center" action
Creates "delete center" form with a select to choose a center to delete.
Adds a new button in the scopes view. Because scopes checkboxes values
maps to ips the only way to specify the center to delete is in the delete
center form itself, using a select input.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index 48770a2..fee8b98 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -11,7 +11,7 @@ from flask import ( from ogcp.forms.action_forms import ( WOLForm, SetupForm, ClientDetailsForm, HardwareForm, SessionForm, ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm, - RoomForm, DeleteRoomForm, CenterForm + RoomForm, DeleteRoomForm, CenterForm, DeleteCenterForm ) from flask_login import ( current_user, LoginManager, @@ -681,6 +681,26 @@ def action_center_add(): else: return render_template('actions/add_center.html', form=form) +@app.route('/action/center/delete', methods=['GET', 'POST']) +@login_required +def action_center_delete(): + form = DeleteCenterForm(request.form) + if request.method == 'POST': + payload = {"id": form.center.data} + r = g.server.post('/center/delete', payload) + if r.status_code != requests.codes.ok: + flash(_('Server replied with error code when deleting the center'), + category='error') + else: + flash(_('Center deleted successfully'), category='info') + return redirect(url_for("scopes")) + else: + r = g.server.get('/scopes') + centers = parse_scopes_from_tree(r.json(), 'center') + centers = [(center['id'], center['name']) for center in centers] + form.center.choices = list(centers) + return render_template('actions/delete_center.html', form=form) + @app.route('/action/room/add', methods=['GET', 'POST']) @login_required def action_room_add(): |