diff options
author | Javier Hernandez <jhernandez@soleta.eu> | 2023-12-14 12:30:16 +0100 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2023-12-14 12:35:01 +0100 |
commit | 24aab951a8373642b36e1063789a20bb05965586 (patch) | |
tree | 8aa57425e643dd19f4ce1cf3c7ee54bded966768 /ogcp/views.py | |
parent | aa6061dad7e90ef9761d2d64940cf38eed51c990 (diff) |
Group images by repos
Make the sidebar from the images menu display the list of repos grouped
by repos
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index b008673..406de44 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -1479,10 +1479,34 @@ def commands(): scopes, clients = get_scopes() return render_template('commands.html', scopes=scopes, clients=clients) +def get_images_grouped_by_repos(): + responses = multi_request('get', '/images') + servers=[] + for resp in responses: + server={} + server['server'] = resp['server'] + images=resp['json']['images'] + all_repos=get_repositories(resp['server']) + repos={} + for image in images: + repo_id=image['repo_id'] + repo_data={} + if repo_id not in repos: + repo_name = [repo['name'] for repo in all_repos + if repo_id == repo['id']][0] + repos[repo_id] = {} + repos[repo_id]['name'] = repo_name + repos[repo_id]['images'] = [image] + else: + repos[repo_id]['images'].append(image) + server['repos'] = repos + servers.append(server) + return servers + @app.route('/images/', methods=['GET']) @login_required def images(): - responses = multi_request('get', '/images') + responses = get_images_grouped_by_repos() return render_template('images.html', responses=responses) @@ -1942,7 +1966,7 @@ def action_image_info(): form.software_id.data = image['software_id'] form.description.data = image['description'] - responses = multi_request('get', '/images') + responses = get_images_grouped_by_repos() return render_template('actions/image_details.html', form=form, responses=responses) @@ -1972,7 +1996,7 @@ def action_image_delete(): return redirect(url_for('images')) image_name, image_id = images[0] server = get_server_from_ip_port(params['image-server']) - responses = multi_request('get', '/images') + responses = get_images_grouped_by_repos() form.ids.data = image_id form.server.data = params['image-server'] if not validate_elements(images, max_len=1): |