summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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():