views: Sort scopes tree alphanumerically

Sort tree that contain the scope information (centers, rooms, clients)
so that they appear in sidebar in alphanumerical order.
master
Javier Hernandez 2023-12-22 10:59:44 +01:00 committed by OpenGnSys Support Team
parent 3587806937
commit 01977dcd66
1 changed files with 13 additions and 0 deletions

View File

@ -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)