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)
This commit is contained in:
parent
dcaf0cc51f
commit
88c087e107
@ -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']
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user