summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2022-08-23 16:15:23 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2022-08-31 15:57:52 +0200
commitea0ce480c70a5eff54bfcb4f33eb339e6b831234 (patch)
tree9e72fc58dd6d37d05d892da07ce6d3687f523ee1
parent3dea9115b14f2a541207369fb5a72b263c94aed1 (diff)
Add a room to a center using the scopes tree
With this commit users can select a center from the scopes tree, and then add a room to that center.
-rw-r--r--ogcp/templates/macros.html6
-rw-r--r--ogcp/views.py14
2 files changed, 17 insertions, 3 deletions
diff --git a/ogcp/templates/macros.html b/ogcp/templates/macros.html
index f67b1a6..0283d26 100644
--- a/ogcp/templates/macros.html
+++ b/ogcp/templates/macros.html
@@ -28,6 +28,12 @@
value="{{ scope["server_ip_port"] }}" onclick="return false;"
{% if scope.get("selected", False) %}checked{% endif %}
name="scope-server" hidden/>
+ {% elif scope["type"] == "center" %}
+ <input class="form-check-input" type="checkbox" form="scopesForm"
+ value="{{ scope["id"] }}"
+ {% if state %}style="filter: grayscale(100%);" onclick="return false;"{% endif %}
+ {% if scope.get("selected", False) %}checked{% endif %}
+ name="scope-center" />
{% elif scope["type"] == "room" %}
<input class="form-check-input" type="checkbox" form="scopesForm"
value="{{ scope["id"] }}"
diff --git a/ogcp/views.py b/ogcp/views.py
index af1df47..72a86bb 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -96,7 +96,8 @@ def validate_elements(elements, min_len=1, max_len=float('inf')):
return valid
def parse_elements(checkboxes_dict):
- unwanted_elements = ['csrf_token', 'scope-server', 'scope-room']
+ unwanted_elements = ['csrf_token', 'scope-server', 'scope-center',
+ 'scope-room']
elements = set()
for key, elements_list in checkboxes_dict.items():
if key not in unwanted_elements:
@@ -1303,10 +1304,17 @@ def action_room_add():
flash(_('Room added successfully'), category='info')
return redirect(url_for("scopes"))
else:
+ params = request.args.to_dict()
+ if not params.get('scope-center'):
+ flash(_('Please, select one center'), category='error')
+ return redirect(url_for('scopes'))
r = g.server.get('/scopes')
+ selected_center_id = params['scope-center']
centers = parse_scopes_from_tree(r.json(), 'center')
- centers = [(center['id'], center['name']) for center in centers]
- form.center.choices = list(centers)
+ selected_center = [(center['id'], center['name']) for center in centers
+ if center['id'] == int(selected_center_id)]
+ form.center.choices = selected_center
+ form.center.render_kw = {'readonly': True}
scopes, clients = get_scopes()
return render_template('actions/add_room.html', form=form,
scopes=scopes)