Merge "Sort image source choices by name for volume"
This commit is contained in:
commit
5daabe542d
@ -252,12 +252,15 @@ class CreateForm(forms.SelfHandlingForm):
|
|||||||
request.user.tenant_id)
|
request.user.tenant_id)
|
||||||
if images:
|
if images:
|
||||||
source_type_choices.append(("image_source", _("Image")))
|
source_type_choices.append(("image_source", _("Image")))
|
||||||
choices = [('', _("Choose an image"))]
|
choices = []
|
||||||
for image in images:
|
for image in images:
|
||||||
image.bytes = image.size
|
image.bytes = image.size
|
||||||
image.size = functions.bytes_to_gigabytes(image.bytes)
|
image.size = functions.bytes_to_gigabytes(image.bytes)
|
||||||
choices.append((image.id, image))
|
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:
|
else:
|
||||||
del self.fields['image_source']
|
del self.fields['image_source']
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user