summaryrefslogtreecommitdiffstats
path: root/ogcp
diff options
context:
space:
mode:
Diffstat (limited to 'ogcp')
-rw-r--r--ogcp/forms/action_forms.py9
-rw-r--r--ogcp/templates/actions/add_room.html15
-rw-r--r--ogcp/templates/scopes.html2
-rw-r--r--ogcp/views.py23
4 files changed, 48 insertions, 1 deletions
diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py
index d1633e2..3bd3ef5 100644
--- a/ogcp/forms/action_forms.py
+++ b/ogcp/forms/action_forms.py
@@ -89,3 +89,12 @@ class ImageCreateForm(FlaskForm):
validators=[InputRequired()])
description = StringField(label=_('Description'))
create = SubmitField(label=_('Create'))
+
+class RoomForm(FlaskForm):
+ center = SelectField(label=_('Center'),
+ validators=[InputRequired()])
+ name = StringField(label=_('Room name'),
+ validators=[InputRequired()])
+ netmask = StringField(label=_('Netmask'),
+ validators=[InputRequired()])
+ submit = SubmitField(label=_('Submit'))
diff --git a/ogcp/templates/actions/add_room.html b/ogcp/templates/actions/add_room.html
new file mode 100644
index 0000000..dffdc87
--- /dev/null
+++ b/ogcp/templates/actions/add_room.html
@@ -0,0 +1,15 @@
+{% extends 'base.html' %}
+{% import "bootstrap/wtf.html" as wtf %}
+
+{% block content %}
+
+<h1 class="m-5">{{_('Add room form')}}</h1>
+
+{{ wtf.quick_form(form,
+ action=url_for('action_room_add'),
+ method='post',
+ button_map={'submit': 'primary'},
+ extra_classes="mx-5") }}
+
+{% endblock %}
+
diff --git a/ogcp/templates/scopes.html b/ogcp/templates/scopes.html
index 0adeca4..df2b535 100644
--- a/ogcp/templates/scopes.html
+++ b/ogcp/templates/scopes.html
@@ -59,6 +59,8 @@
formaction="{{ url_for('action_image_create') }}" formmethod="get">
<input class="dropdown-item" type="submit" value="{{ _('Set boot mode') }}"
formaction="{{ url_for('action_mode') }}" formmethod="get">
+ <input class="dropdown-item" type="submit" value="{{ _('Add room') }}"
+ formaction="{{ url_for('action_room_add') }}" formmethod="get">
</div>
</div>
</form>
diff --git a/ogcp/views.py b/ogcp/views.py
index c66ada8..73b1fcb 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -3,7 +3,7 @@ from flask import (
)
from ogcp.forms.action_forms import (
WOLForm, PartitionForm, ClientDetailsForm, HardwareForm, SessionForm,
- ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm
+ ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm, RoomForm
)
from flask_login import (
current_user, LoginManager,
@@ -653,3 +653,24 @@ def action_refresh():
else:
flash(_('Refresh request processed successfully'), category='info')
return redirect(url_for("scopes"))
+
+@app.route('/action/room/add', methods=['GET', 'POST'])
+@login_required
+def action_room_add():
+ form = RoomForm(request.form)
+ if request.method == 'POST':
+ payload = {"center": int(form.center.data),
+ "name": form.name.data,
+ "netmask": form.netmask.data}
+ r = g.server.post('/room/add', payload)
+ if r.status_code != requests.codes.ok:
+ flash(_('Server replied with error code when adding the room'), category='error')
+ else:
+ flash(_('Room added 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/add_room.html', form=form)