From 76e06637c1121c8f9fe84e0fb4be769367568e2b Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Thu, 25 Jul 2013 12:54:01 +0800 Subject: Add Image Source Field to choose Location or File Change-Id: I79546c5c2d10b7d6cefdca084f4f7a13ce2939d5 Fixes: bug #1185671 --- .../project/images_and_snapshots/images/forms.py | 17 +++++++++++++++++ .../project/images_and_snapshots/images/tests.py | 3 +++ 2 files changed, 20 insertions(+) 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 ac325d43..c8876374 100644 --- a/openstack_dashboard/dashboards/project/images_and_snapshots/images/forms.py +++ b/openstack_dashboard/dashboards/project/images_and_snapshots/images/forms.py @@ -44,13 +44,30 @@ class CreateImageForm(forms.SelfHandlingForm): description = forms.CharField(widget=forms.widgets.Textarea(), label=_("Description"), required=False) + + source_type = forms.ChoiceField( + label=_('Image Source'), + choices=[('url', _('Image Location')), + ('file', _('Image File'))], + widget=forms.Select(attrs={ + 'class': 'switchable', + 'data-slug': 'source'})) + copy_from = forms.CharField(max_length="255", label=_("Image Location"), help_text=_("An external (HTTP) URL to load " "the image from."), + widget=forms.TextInput(attrs={ + 'class': 'switched', + 'data-switch-on': 'source', + 'data-source-url': _('Image Location')}), required=False) image_file = forms.FileField(label=_("Image File"), help_text=("A local image to upload."), + widget=forms.FileInput(attrs={ + 'class': 'switched', + 'data-switch-on': 'source', + 'data-source-file': _('Image File')}), required=False) disk_format = forms.ChoiceField(label=_('Format'), required=True, 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 b4d7626f..585804cb 100644 --- a/openstack_dashboard/dashboards/project/images_and_snapshots/images/tests.py +++ b/openstack_dashboard/dashboards/project/images_and_snapshots/images/tests.py @@ -50,6 +50,7 @@ class CreateImageFormTests(test.TestCase): """ post = { 'name': u'Ubuntu 11.10', + 'source_type': u'file', 'description': u'Login with admin/admin', 'disk_format': u'qcow2', 'minimum_disk': 15, @@ -82,6 +83,7 @@ class ImageViewTests(test.TestCase): data = { 'name': u'Ubuntu 11.10', 'description': u'Login with admin/admin', + 'source_type': u'url', 'copy_from': u'http://cloud-images.ubuntu.com/releases/' u'oneiric/release/ubuntu-11.10-server-cloudimg' u'-amd64-disk1.img', @@ -121,6 +123,7 @@ class ImageViewTests(test.TestCase): data = { 'name': u'Test Image', 'description': u'Login with admin/admin', + 'source_type': u'file', 'image_file': temp_file, 'disk_format': u'qcow2', 'minimum_disk': 15, -- cgit v1.2.1