From 8ded0be73d9668e68d7862a31645b15b377b90c7 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Thu, 6 Jun 2013 14:04:25 +0800 Subject: [PATCH] Add general description field in image properties It would be beneficial for us to be able to add descriptions to the image file. Change-Id: I8e5f9ce423f1bc76e559ffb437f255fd9717902e Fixes: bug #1180861 --- .../project/images_and_snapshots/images/forms.py | 13 ++++++++++++- .../project/images_and_snapshots/images/tests.py | 7 +++++++ .../project/images_and_snapshots/images/views.py | 1 + .../images/_detail_overview.html | 4 ++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/openstack_dashboard/dashboards/project/images_and_snapshots/images/forms.py b/openstack_dashboard/dashboards/project/images_and_snapshots/images/forms.py index 626d182d8..ac325d43b 100644 --- a/openstack_dashboard/dashboards/project/images_and_snapshots/images/forms.py +++ b/openstack_dashboard/dashboards/project/images_and_snapshots/images/forms.py @@ -41,6 +41,9 @@ LOG = logging.getLogger(__name__) class CreateImageForm(forms.SelfHandlingForm): name = forms.CharField(max_length="255", label=_("Name"), required=True) + description = forms.CharField(widget=forms.widgets.Textarea(), + label=_("Description"), + required=False) copy_from = forms.CharField(max_length="255", label=_("Image Location"), help_text=_("An external (HTTP) URL to load " @@ -121,8 +124,11 @@ class CreateImageForm(forms.SelfHandlingForm): 'container_format': container_format, 'min_disk': (data['minimum_disk'] or 0), 'min_ram': (data['minimum_ram'] or 0), - 'name': data['name']} + 'name': data['name'], + 'properties': {}} + if data['description']: + meta['properties']['description'] = data['description'] if settings.HORIZON_IMAGES_ALLOW_UPLOAD and data['image_file']: meta['data'] = self.files['image_file'] else: @@ -141,6 +147,9 @@ class CreateImageForm(forms.SelfHandlingForm): class UpdateImageForm(forms.SelfHandlingForm): image_id = forms.CharField(widget=forms.HiddenInput()) name = forms.CharField(max_length="255", label=_("Name")) + description = forms.CharField(widget=forms.widgets.Textarea(), + label=_("Description"), + required=False) kernel = forms.CharField(max_length="36", label=_("Kernel ID"), required=False, widget=forms.TextInput( @@ -177,6 +186,8 @@ class UpdateImageForm(forms.SelfHandlingForm): 'container_format': container_format, 'name': data['name'], 'properties': {}} + if data['description']: + meta['properties']['description'] = data['description'] if data['kernel']: meta['properties']['kernel_id'] = data['kernel'] if data['ramdisk']: diff --git a/openstack_dashboard/dashboards/project/images_and_snapshots/images/tests.py b/openstack_dashboard/dashboards/project/images_and_snapshots/images/tests.py index 27ff36912..add9d8ebb 100644 --- a/openstack_dashboard/dashboards/project/images_and_snapshots/images/tests.py +++ b/openstack_dashboard/dashboards/project/images_and_snapshots/images/tests.py @@ -48,6 +48,7 @@ class CreateImageFormTests(test.TestCase): """ post = { 'name': u'Ubuntu 11.10', + 'description': u'Login with admin/admin', 'disk_format': u'qcow2', 'minimum_disk': 15, 'minimum_ram': 512, @@ -78,6 +79,7 @@ class ImageViewTests(test.TestCase): def test_image_create_post_copy_from(self): data = { 'name': u'Ubuntu 11.10', + 'description': u'Login with admin/admin', 'copy_from': u'http://cloud-images.ubuntu.com/releases/' u'oneiric/release/ubuntu-11.10-server-cloudimg' u'-amd64-disk1.img', @@ -96,6 +98,8 @@ class ImageViewTests(test.TestCase): protected=False, min_disk=data['minimum_disk'], min_ram=data['minimum_ram'], + properties={ + 'description': data['description']}, name=data['name']). \ AndReturn(self.images.first()) self.mox.ReplayAll() @@ -114,6 +118,7 @@ class ImageViewTests(test.TestCase): temp_file.seek(0) data = { 'name': u'Test Image', + 'description': u'Login with admin/admin', 'image_file': temp_file, 'disk_format': u'qcow2', 'minimum_disk': 15, @@ -129,6 +134,8 @@ class ImageViewTests(test.TestCase): protected=False, min_disk=data['minimum_disk'], min_ram=data['minimum_ram'], + properties={ + 'description': data['description']}, name=data['name'], data=IsA(InMemoryUploadedFile)). \ AndReturn(self.images.first()) diff --git a/openstack_dashboard/dashboards/project/images_and_snapshots/images/views.py b/openstack_dashboard/dashboards/project/images_and_snapshots/images/views.py index 4274afdcd..e729a598d 100644 --- a/openstack_dashboard/dashboards/project/images_and_snapshots/images/views.py +++ b/openstack_dashboard/dashboards/project/images_and_snapshots/images/views.py @@ -74,6 +74,7 @@ class UpdateView(forms.ModalFormView): image = self.get_object() return {'image_id': self.kwargs['image_id'], 'name': image.name, + 'description': image.properties.get('description', ''), 'kernel': image.properties.get('kernel_id', ''), 'ramdisk': image.properties.get('ramdisk_id', ''), 'architecture': image.properties.get('architecture', ''), diff --git a/openstack_dashboard/dashboards/project/images_and_snapshots/templates/images_and_snapshots/images/_detail_overview.html b/openstack_dashboard/dashboards/project/images_and_snapshots/templates/images_and_snapshots/images/_detail_overview.html index a0c258dec..e848ac877 100644 --- a/openstack_dashboard/dashboards/project/images_and_snapshots/templates/images_and_snapshots/images/_detail_overview.html +++ b/openstack_dashboard/dashboards/project/images_and_snapshots/templates/images_and_snapshots/images/_detail_overview.html @@ -8,6 +8,10 @@
{% trans "Name" %}
{{ image.name|default:_("None") }}
+ {% if image.properties.description %} +
{% trans "Description" %}
+
{{ image.properties.description }}
+ {% endif %}
{% trans "ID" %}
{{ image.id|default:_("None") }}
{% trans "Status" %}