From 88c087e10743d803aa5ca97ae4523bb35285eca8 Mon Sep 17 00:00:00 2001 From: Tobias Urdin Date: Tue, 20 Aug 2024 11:09:50 +0200 Subject: [PATCH] Sort image source choices by name for volume When creating a volume and selecting to use image as a source we get a dropdown of the images that we can select but this list is not sorted based on image name. This changes so that it's sorted by the image name ascending to match the instance launch dialog that already lists images in ascending order by name. Change-Id: I17212e460e307e08b2b6c2a8a68a14ffde8cc04b (cherry picked from commit c18f9d90aeb9a5fcbb79318e1beef4b3bffac501) --- openstack_dashboard/dashboards/project/volumes/forms.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/openstack_dashboard/dashboards/project/volumes/forms.py b/openstack_dashboard/dashboards/project/volumes/forms.py index 3d89d365f5..4b6c9ca211 100644 --- a/openstack_dashboard/dashboards/project/volumes/forms.py +++ b/openstack_dashboard/dashboards/project/volumes/forms.py @@ -252,12 +252,15 @@ class CreateForm(forms.SelfHandlingForm): request.user.tenant_id) if images: source_type_choices.append(("image_source", _("Image"))) - choices = [('', _("Choose an image"))] + choices = [] for image in images: image.bytes = image.size image.size = functions.bytes_to_gigabytes(image.bytes) choices.append((image.id, image)) - self.fields['image_source'].choices = choices + sorted_choices = sorted( + choices, key=lambda x: (x[1].name if x[1].name else '')) + sorted_choices.insert(0, ('', _("Choose an image"))) + self.fields['image_source'].choices = sorted_choices else: del self.fields['image_source']