Browse Source

Move image_field_data method in-tree

this was removed in Horizon as 'not needed' in
26eebd4abb
however it is used to form a hint for glance.image constraint
in heat-dashboard.

Just copy-paste the method as it existed in horizon with minimal
adaptations.

Change-Id: I23fd3f45f0ce5b67691991336e727c377ca36281
(cherry picked from commit 953369c870)
changes/20/760120/1
Pavlo Shchelokovskyy 8 months ago
committed by Pavlo Shchelokovskyy
parent
commit
e601aab1a3
1 changed files with 32 additions and 1 deletions
  1. +32
    -1
      heat_dashboard/content/stacks/forms.py

+ 32
- 1
heat_dashboard/content/stacks/forms.py View File

@ -15,6 +15,7 @@ import logging
import django
from django.conf import settings
from django.template.defaultfilters import filesizeformat
from django.utils import html
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.debug import sensitive_variables
@ -35,6 +36,36 @@ from openstack_dashboard.dashboards.project.instances \
LOG = logging.getLogger(__name__)
def image_field_data(request, include_empty_option=False):
"""Returns a list of tuples of all images.
Generates a sorted list of images available. And returns a list of
(id, name) tuples.
:param request: django http request object
:param include_empty_option: flag to include a empty tuple in the front of
the list
:return: list of (id, name) tuples
"""
try:
images = image_utils.get_available_images(
request, request.user.project_id)
except Exception:
exceptions.handle(request, _('Unable to retrieve images'))
images.sort(key=lambda c: c.name)
images_list = [('', _('Select Image'))]
for image in images:
image_label = u"{} ({})".format(image.name, filesizeformat(image.size))
images_list.append((image.id, image_label))
if not images:
return [("", _("No images available")), ]
return images_list
def create_upload_form_attributes(prefix, input_type, name):
"""Creates attribute dicts for the switchable upload form
@ -416,7 +447,7 @@ class CreateStackForm(forms.SelfHandlingForm):
if custom_type == 'nova.keypair':
return instance_utils.keypair_field_data(self.request, True)
if custom_type == 'glance.image':
return image_utils.image_field_data(self.request, True)
return image_field_data(self.request, True)
if custom_type == 'nova.flavor':
return instance_utils.flavor_field_data(self.request, True)
return []


Loading…
Cancel
Save