From 792f8cbe4ac6f39aa41b0905e3b68f2a8c1e5fb1 Mon Sep 17 00:00:00 2001 From: Keigo Noha Date: Thu, 15 Apr 2021 11:49:56 +0900 Subject: [PATCH] Set False to include_empty_option In _populate_custom_choices(), all methods called at the method have True as a second argument. It means that the default values sepcified in a stack are not shown as default when launch stack form. The fileds always show 'Select Flavor/Image/Network'. Users doesn't expect to choose default value by hand. This change shows the default values defined at a template. Also, image_field_data() doesn't use parameter, include_empty_option. This change modfies the method to change the behavior based on the parameter. Closes-Bug: #1619465 Change-Id: I4b6bef322a668a805abcd4bc472d30f6d1df3a0a --- heat_dashboard/content/stacks/forms.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/heat_dashboard/content/stacks/forms.py b/heat_dashboard/content/stacks/forms.py index d0f7760e..dcff6d1f 100644 --- a/heat_dashboard/content/stacks/forms.py +++ b/heat_dashboard/content/stacks/forms.py @@ -55,7 +55,7 @@ def image_field_data(request, include_empty_option=False): except Exception: exceptions.handle(request, _('Unable to retrieve images')) images.sort(key=lambda c: c.name) - images_list = [('', _('Select Image'))] + images_list = [] for image in images: image_label = u"{} ({})".format(image.name, filesizeformat(image.size)) images_list.append((image.id, image_label)) @@ -63,6 +63,9 @@ def image_field_data(request, include_empty_option=False): if not images: return [("", _("No images available")), ] + if include_empty_option: + return [("", _("Select Image")), ] + images_list + return images_list @@ -443,13 +446,13 @@ class CreateStackForm(forms.SelfHandlingForm): def _populate_custom_choices(self, custom_type): if custom_type == 'neutron.network': - return instance_utils.network_field_data(self.request, True) + return instance_utils.network_field_data(self.request, False) if custom_type == 'nova.keypair': - return instance_utils.keypair_field_data(self.request, True) + return instance_utils.keypair_field_data(self.request, False) if custom_type == 'glance.image': - return image_field_data(self.request, True) + return image_field_data(self.request, False) if custom_type == 'nova.flavor': - return instance_utils.flavor_field_data(self.request, True) + return instance_utils.flavor_field_data(self.request, False) return []