summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py43
1 files changed, 35 insertions, 8 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index fa6ebc2..dd16e79 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -1242,14 +1242,13 @@ def action_folder_delete():
form.submit.render_kw = {"formaction": url_for('action_folder_delete')}
scopes, unused = get_scopes()
- folder = find_folder(int(folder_id), scopes)
- if not folder:
- flash(_('Folder was not found'), category='info')
- return redirect(url_for("scopes"))
- form.name.data = folder['name']
form.name.render_kw = {'readonly': True}
+
+ ancestors, children = get_scope_context(int(folder_id), 'folder', scopes)
+ form.name.data = ancestors[len(ancestors)-1]
+
return render_template('actions/folder_delete.html', form=form,
- parent="scopes.html", scopes=scopes, folder_content=folder['scope'])
+ parent="scopes.html", scopes=scopes, ancestors=ancestors, children=children)
@app.route('/action/folder/add', methods=['GET'])
@login_required
@@ -1885,6 +1884,32 @@ def action_center_add():
return render_template('actions/add_center.html', form=form,
scopes=scopes)
+def get_scope_context_rec(elem_id, elem_type, scopes, ancestors):
+ if not scopes:
+ return ([], None)
+ res = None
+ for s in scopes:
+ if s['type'] == elem_type and int(s['id']) == elem_id:
+ ancestors.append(s['name'])
+ return (ancestors, s)
+ ancestors_tmp = list(ancestors)
+ ancestors_tmp.append(s['name'])
+ ancestors_tmp, elem = get_scope_context_rec(elem_id, elem_type, s['scope'], ancestors_tmp)
+ if elem:
+ res = (ancestors_tmp, elem)
+ break
+ if res:
+ return res
+ else:
+ return ([], None)
+
+def get_scope_context(elem_id, elem_type, scopes):
+ ancestors, elem = get_scope_context_rec(elem_id, elem_type, scopes['scope'], [])
+ children = []
+ for c in elem['scope']:
+ children.append({'name':c['name'], 'type':c['type']})
+ return (ancestors, children)
+
@app.route('/action/center/delete', methods=['GET', 'POST'])
@login_required
def action_center_delete():
@@ -1919,8 +1944,9 @@ def action_center_delete():
form.center.render_kw = {'readonly': True}
form.server.data = params['scope-server']
scopes, clients = get_scopes()
+ ancestors, children = get_scope_context(int(selected_center_id), 'center', scopes)
return render_template('actions/delete_center.html', form=form,
- scopes=scopes)
+ scopes=scopes, ancestors=ancestors, children=children)
@app.route('/action/room/add', methods=['GET', 'POST'])
@login_required
@@ -2002,8 +2028,9 @@ def action_room_delete():
form.room.render_kw = {'readonly': True}
form.server.data = params['scope-server']
scopes, clients = get_scopes()
+ ancestors, children = get_scope_context(int(selected_room_id), 'room', scopes)
return render_template('actions/delete_room.html', form=form,
- scopes=scopes)
+ scopes=scopes, ancestors=ancestors, children=children)
@app.route('/commands/', methods=['GET'])
@login_required