summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Hernandez <jhernandez@soleta.eu>2023-12-22 10:59:44 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2023-12-22 11:19:21 +0100
commit01977dcd669d7eedc4fde45f8e9a07e991acf72e (patch)
tree605a0e986d7527f713c58c166aefdc054f216e5d
parent3587806937f7fd1bf2af38f6a894be13f09666a3 (diff)
views: Sort scopes tree alphanumerically
Sort tree that contain the scope information (centers, rooms, clients) so that they appear in sidebar in alphanumerical order.
-rw-r--r--ogcp/views.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 7336142..9a88bbc 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -236,6 +236,18 @@ def get_server_from_ip_port(str_ip_port):
raise Exception('Server with address ' + str_ip_port + 'is not configured')
+def sort_scopes_recursive(ls_scopes):
+ for scope in ls_scopes:
+ if len(scope['scope']) != 0:
+ sorted_ls = sort_scopes_recursive(scope['scope'])
+ scope['scope'] = sorted_ls
+ return sorted(ls_scopes, key=lambda s: s['name'].lower())
+
+def sort_scopes(scopes):
+ all_scopes={}
+ ls = sort_scopes_recursive(scopes['scope'])
+ all_scopes['scope'] = ls
+ return all_scopes
def get_scopes(ips=set()):
list_scopes = []
@@ -250,6 +262,7 @@ def get_scopes(ips=set()):
server_scope.update(scopes)
list_scopes.append(server_scope)
all_scopes = {'scope': list_scopes}
+ all_scopes = sort_scopes(all_scopes)
if current_user.scopes:
allowed_scopes = []
get_allowed_scopes(all_scopes, allowed_scopes)