From 01977dcd669d7eedc4fde45f8e9a07e991acf72e Mon Sep 17 00:00:00 2001 From: Javier Hernandez Date: Fri, 22 Dec 2023 10:59:44 +0100 Subject: views: Sort scopes tree alphanumerically Sort tree that contain the scope information (centers, rooms, clients) so that they appear in sidebar in alphanumerical order. --- ogcp/views.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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) -- cgit v1.2.3-18-g5258