From 8e16c319528972048247a903f7acace6c4eeefa9 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Tue, 6 Aug 2024 09:24:44 +0200 Subject: views: sort images based on alphabetical name order Show images in alphabetical order in every views listing images. The only exception is the dashboard as it shows them from newer to older. --- ogcp/views.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'ogcp') diff --git a/ogcp/views.py b/ogcp/views.py index 2a89d01..6b8607e 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -834,6 +834,12 @@ def get_images_from_repo(server, repo_id): res.append(image) return res +def get_image_key(image): + return image['name'] + +def sort_images(images): + images.sort(key=get_image_key, reverse=False) + def get_clients_repo(server, ips): repo_id=None for ip in ips: @@ -984,6 +990,8 @@ def action_image_restore(): except ServerErrorCode: return ogserver_error('commands') + sort_images(images) + for image in images: form.image.choices.append((image['id'], image['name'])) @@ -2431,6 +2439,8 @@ def action_image_update(): except ServerErrorCode: return ogserver_error('commands') + sort_images(images) + for image in images: form.image.choices.append((image['id'], image['name'])) @@ -2891,6 +2901,9 @@ def get_images_grouped_by_repos(): except ServerErrorCode: continue repos={} + + sort_images(images) + for image in images: repo_id=image['repo_id'] repo_data={} -- cgit v1.2.3-18-g5258