summaryrefslogtreecommitdiffstats
path: root/ogcp
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2021-07-30 12:15:29 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2021-07-30 13:01:38 +0200
commit9d98cf0423e7fa0e74bc06ae8d47c9d4896564c1 (patch)
treed514d393c909e80dc2f50e9f521deff02d33c571 /ogcp
parent95c113f0674bda60cce7f1cc82ec1bf2777ed170 (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')
-rw-r--r--ogcp/forms/action_forms.py5
-rw-r--r--ogcp/templates/scopes.html2
-rw-r--r--ogcp/views.py22
3 files changed, 28 insertions, 1 deletions
diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py
index c5b4909..1be2120 100644
--- a/ogcp/forms/action_forms.py
+++ b/ogcp/forms/action_forms.py
@@ -109,6 +109,11 @@ class CenterForm(FlaskForm):
comment = StringField(label=_('Comment'))
submit = SubmitField(label=_('Submit'))
+class DeleteCenterForm(FlaskForm):
+ center = SelectField(label=_('Center'),
+ validators=[InputRequired()])
+ submit = SubmitField(label=_('Submit'))
+
class RoomForm(FlaskForm):
center = SelectField(label=_('Center'),
validators=[InputRequired()])
diff --git a/ogcp/templates/scopes.html b/ogcp/templates/scopes.html
index 07d9b7f..8ab30c0 100644
--- a/ogcp/templates/scopes.html
+++ b/ogcp/templates/scopes.html
@@ -26,4 +26,6 @@
form="scopesForm" formaction="{{ url_for('action_client_delete') }}" formmethod="post">
<input class="btn btn-light" type="submit" value="{{ _('Delete room') }}"
form="scopesForm" formaction="{{ url_for('action_room_delete') }}" formmethod="get">
+ <input class="btn btn-light" type="submit" value="{{ _('Delete center') }}"
+ form="scopesForm" formaction="{{ url_for('action_center_delete') }}" formmethod="get">
{% endblock %}
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():