diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-09-04 14:15:38 +0200 |
---|---|---|
committer | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-09-04 15:36:09 +0200 |
commit | 6e1d266daf6192428a2369804688504e41e0b1a8 (patch) | |
tree | 6570f68074ad5c77b8d64a8209dce053c343a2d9 /ogcp/views.py | |
parent | 23b49f0a6aa2579b174c003051af4ad1066b8014 (diff) |
views: sort repositories by name
Show repositories sorted in an alphanumeric fashion inside the
sidebar of /images and the respective child views.
Sort repositories in the sidebar of /repos.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index 705605b..c78dc24 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -257,6 +257,14 @@ def get_repositories(server): repositories = r.json()['repositories'] return repositories +def get_all_repositories(): + data = multi_request('get', '/repositories') + for item in data: + repositories = item['json']['repositories'] + sorted_repositories = sorted(repositories, key=lambda repo: repo['name']) + item['json']['repositories'] = sorted_repositories + return data + def parse_scopes_from_tree(tree, scope_type): scopes = [] @@ -3012,6 +3020,9 @@ def commands(): scopes, clients = get_scopes() return render_template('commands.html', scopes=scopes, clients=clients) +def _get_sorted_repos(repos): + return dict(sorted(repos.items(), key=lambda item: item[1]['name'])) + def get_images_grouped_by_repos(): responses = multi_request('get', '/images') servers=[] @@ -3043,7 +3054,7 @@ def get_images_grouped_by_repos(): repos[repo_id]['images'] = [image] else: repos[repo_id]['images'].append(image) - server['repos'] = repos + server['repos'] = _get_sorted_repos(repos) servers.append(server) return servers @@ -3057,7 +3068,7 @@ def images(): @app.route('/repos/', methods=['GET']) @login_required def manage_repos(): - responses = multi_request('get', '/repositories') + responses = get_all_repositories() return render_template('repos.html', repos_resp=responses) def repo_addr_is_valid(form): @@ -3124,7 +3135,7 @@ def action_repo_add(): form.server.data = params['repos-server'] form.addr.append_entry('') - responses = multi_request('get', '/repositories') + responses = get_all_repositories() return render_template('actions/repos_add.html', form=form, repos_resp=responses) @@ -3179,7 +3190,7 @@ def action_repo_update(): for addr in repository['addr']: form.addr.append_entry(addr) - responses = multi_request('get', '/repositories') + responses = get_all_repositories() return render_template('actions/repos_update.html', form=form, repos_resp=responses) @@ -3232,7 +3243,7 @@ def action_repo_delete(): form.addr.append_entry(addr) for field in form.addr: field.render_kw = {'readonly': True} - responses = multi_request('get', '/repositories') + responses = get_all_repositories() return render_template('actions/delete_repo.html', form=form, repos_resp=responses) @@ -3269,7 +3280,7 @@ def action_repo_info(): for field in form.addr: field.render_kw = {'readonly': True} form.submit.render_kw = {"style": "visibility:hidden;"} - responses = multi_request('get', '/repositories') + responses = get_all_repositories() return render_template('actions/repo_details.html', form=form, repos_resp=responses) |