From 2415de13a240ccfa94770c8c1dc805fc00c90f48 Mon Sep 17 00:00:00 2001 From: Cindy Lu Date: Thu, 12 Feb 2015 13:57:23 -0800 Subject: [PATCH] Clean modal forms for Images panel Refactoring Images modals. Based on merged patch: https://review.openstack.org/#/c/123472/ Co-Authored-By: Rob Cresswell Co-Authored-By: Cindy Lu Change-Id: I289dd4876e85f0ea1aa9f1d88c4915c897e8ea5b Partially-Implements: blueprint form-template-to-view --- .../images/templates/images/_create.html | 39 +++++-------------- .../images/templates/images/_update.html | 21 +--------- .../templates/images/_update_metadata.html | 10 ----- .../dashboards/admin/images/views.py | 7 ++++ .../dashboards/project/images/images/views.py | 10 +++++ .../project/images/snapshots/views.py | 7 ++++ .../templates/images/images/_create.html | 9 ----- .../templates/images/images/_update.html | 11 ------ .../templates/images/snapshots/_create.html | 25 ++---------- 9 files changed, 38 insertions(+), 101 deletions(-) diff --git a/openstack_dashboard/dashboards/admin/images/templates/images/_create.html b/openstack_dashboard/dashboards/admin/images/templates/images/_create.html index f31c0a6807..ef615e1688 100644 --- a/openstack_dashboard/dashboards/admin/images/templates/images/_create.html +++ b/openstack_dashboard/dashboards/admin/images/templates/images/_create.html @@ -1,36 +1,17 @@ {% extends "horizon/common/_modal_form.html" %} {% load i18n %} -{% load url from future %} -{% block form_id %}create_image_form{% endblock %} {% block ng_controller %}ImageFormCtrl{% endblock %} -{% block form_action %}{% url 'horizon:admin:images:create' %}{% endblock %} {% block form_attrs %}enctype="multipart/form-data"{% endblock %} -{% block modal-header %}{% trans "Create An Image" %}{% endblock %} - -{% block modal-body %} -
-
- {% include "horizon/common/_form_fields.html" %} -
-
-
-

{% trans "Description:" %}

-

- {% trans "Specify an image to upload to the Image Service." %} -

-

- {% trans "Currently only images available via an HTTP URL are supported. The image location must be accessible to the Image Service. Compressed image binaries are supported (.zip and .tar.gz.)" %} -

-

- {% trans "Please note: " %} - {% trans "The Image Location field MUST be a valid and direct URL to the image binary. URLs that redirect or serve error pages will result in unusable images." %} -

-
-{% endblock %} - -{% block modal-footer %} - - {% trans "Cancel" %} +{% block modal-body-right %} +

{% trans "Description:" %}

+

{% trans "Specify an image to upload to the Image Service." %}

+

+ {% trans "Currently only images available via an HTTP URL are supported. The image location must be accessible to the Image Service. Compressed image binaries are supported (.zip and .tar.gz.)" %} +

+

+ {% trans "Please note: " %} + {% trans "The Image Location field MUST be a valid and direct URL to the image binary. URLs that redirect or serve error pages will result in unusable images." %} +

{% endblock %} diff --git a/openstack_dashboard/dashboards/admin/images/templates/images/_update.html b/openstack_dashboard/dashboards/admin/images/templates/images/_update.html index 3151c170b1..fa4b10468c 100644 --- a/openstack_dashboard/dashboards/admin/images/templates/images/_update.html +++ b/openstack_dashboard/dashboards/admin/images/templates/images/_update.html @@ -1,26 +1,7 @@ {% extends "horizon/common/_modal_form.html" %} {% load i18n %} -{% load url from future %} -{% block form_id %}update_image_form{% endblock %} -{% block form_action %}{% url 'horizon:admin:images:update' image.id %}{% endblock %} - -{% block modal_id %}update_image_modal{% endblock %} -{% block modal-header %}{% trans "Update Image" %}{% endblock %} - -{% block modal-body %} -
-
- {% include "horizon/common/_form_fields.html" %} -
-
-
+{% block modal-body-right %}

{% trans "Description:" %}

{% trans "Edit the image details." %}

-
-{% endblock %} - -{% block modal-footer %} - - {% trans "Cancel" %} {% endblock %} diff --git a/openstack_dashboard/dashboards/admin/images/templates/images/_update_metadata.html b/openstack_dashboard/dashboards/admin/images/templates/images/_update_metadata.html index b16dd2c7f9..6ff460c6e2 100644 --- a/openstack_dashboard/dashboards/admin/images/templates/images/_update_metadata.html +++ b/openstack_dashboard/dashboards/admin/images/templates/images/_update_metadata.html @@ -1,11 +1 @@ {% extends 'horizon/common/_modal_form_update_metadata.html' %} -{% load i18n %} -{% load url from future %} -{% block title %}{% trans "Update Image Metadata" %}{% endblock %} - -{% block page_header %} - {% include "horizon/common/_page_header.html" with title=_("Update Image Metadata") %} -{% endblock page_header %} - -{% block form_action %}{% url 'horizon:admin:images:update_metadata' id %}{% endblock %} -{% block modal-header %}{% trans "Update Metadata" %}{% endblock %} diff --git a/openstack_dashboard/dashboards/admin/images/views.py b/openstack_dashboard/dashboards/admin/images/views.py index a067afbd90..13cd3f34a1 100644 --- a/openstack_dashboard/dashboards/admin/images/views.py +++ b/openstack_dashboard/dashboards/admin/images/views.py @@ -110,6 +110,7 @@ class IndexView(tables.DataTableView): class CreateView(views.CreateView): template_name = 'admin/images/create.html' form_class = project_forms.AdminCreateImageForm + submit_url = reverse_lazy('horizon:admin:images:create') success_url = reverse_lazy('horizon:admin:images:index') page_title = _("Create An Image") @@ -117,6 +118,7 @@ class CreateView(views.CreateView): class UpdateView(views.UpdateView): template_name = 'admin/images/update.html' form_class = project_forms.AdminUpdateImageForm + submit_url = "horizon:admin:images:update" success_url = reverse_lazy('horizon:admin:images:index') page_title = _("Update Image") @@ -128,7 +130,10 @@ class DetailView(views.DetailView): class UpdateMetadataView(forms.ModalFormView): template_name = "admin/images/update_metadata.html" + modal_header = _("Update Image") + form_id = "update_image_form" form_class = project_forms.UpdateMetadataForm + submit_url = "horizon:admin:images:update_metadata" success_url = reverse_lazy('horizon:admin:images:index') page_title = _("Update Image Metadata") @@ -146,6 +151,8 @@ class UpdateMetadataView(forms.ModalFormView): for (k, v) in image.properties.iteritems() if k not in reserved_props) context['existing_metadata'] = json.dumps(image.properties) + args = (self.kwargs['id'],) + context['submit_url'] = reverse(self.submit_url, args=args) resource_type = 'OS::Glance::Image' namespaces = [] diff --git a/openstack_dashboard/dashboards/project/images/images/views.py b/openstack_dashboard/dashboards/project/images/images/views.py index 2bf34bdafe..33213c2101 100644 --- a/openstack_dashboard/dashboards/project/images/images/views.py +++ b/openstack_dashboard/dashboards/project/images/images/views.py @@ -40,6 +40,10 @@ from openstack_dashboard.dashboards.project.images.images \ class CreateView(forms.ModalFormView): form_class = project_forms.CreateImageForm + form_id = "create_image_form" + modal_header = _("Create An Image") + submit_label = _("Create Image") + submit_url = reverse_lazy('horizon:project:images:images:create') template_name = 'project/images/images/create.html' context_object_name = 'image' success_url = reverse_lazy("horizon:project:images:index") @@ -48,6 +52,10 @@ class CreateView(forms.ModalFormView): class UpdateView(forms.ModalFormView): form_class = project_forms.UpdateImageForm + form_id = "update_image_form" + modal_header = _("Update Image") + submit_label = _("Update Image") + submit_url = "horizon:project:images:images:update" template_name = 'project/images/images/update.html' success_url = reverse_lazy("horizon:project:images:index") page_title = _("Update Image") @@ -64,6 +72,8 @@ class UpdateView(forms.ModalFormView): def get_context_data(self, **kwargs): context = super(UpdateView, self).get_context_data(**kwargs) context['image'] = self.get_object() + args = (self.kwargs['image_id'],) + context['submit_url'] = reverse(self.submit_url, args=args) return context def get_initial(self): diff --git a/openstack_dashboard/dashboards/project/images/snapshots/views.py b/openstack_dashboard/dashboards/project/images/snapshots/views.py index dd88c193ea..2daa8f6a91 100644 --- a/openstack_dashboard/dashboards/project/images/snapshots/views.py +++ b/openstack_dashboard/dashboards/project/images/snapshots/views.py @@ -35,6 +35,11 @@ from openstack_dashboard.dashboards.project.images.snapshots \ class CreateView(forms.ModalFormView): form_class = project_forms.CreateSnapshot + form_id = "create_snapshot_form" + modal_id = "create_snapshot_modal" + modal_header = _("Create Snapshot") + submit_label = _("Create Snapshot") + submit_url = "horizon:project:images:snapshots:create" template_name = 'project/images/snapshots/create.html' success_url = reverse_lazy("horizon:project:images:index") page_title = _("Create a Snapshot") @@ -56,4 +61,6 @@ class CreateView(forms.ModalFormView): def get_context_data(self, **kwargs): context = super(CreateView, self).get_context_data(**kwargs) context['instance'] = self.get_object() + args = (self.kwargs['instance_id'],) + context['submit_url'] = reverse(self.submit_url, args=args) return context diff --git a/openstack_dashboard/dashboards/project/images/templates/images/images/_create.html b/openstack_dashboard/dashboards/project/images/templates/images/images/_create.html index 6c665419de..43d1850a2a 100644 --- a/openstack_dashboard/dashboards/project/images/templates/images/images/_create.html +++ b/openstack_dashboard/dashboards/project/images/templates/images/images/_create.html @@ -1,13 +1,9 @@ {% extends "horizon/common/_modal_form.html" %} {% load i18n %} -{% load url from future %} -{% block form_id %}create_image_form{% endblock %} {% block ng_controller %}ImageFormCtrl{% endblock %} -{% block form_action %}{% url 'horizon:project:images:images:create' %}{% endblock %} {% block form_attrs %}enctype="multipart/form-data"{% endblock %} -{% block modal-header %}{% trans "Create An Image" %}{% endblock %} {% block modal-body-right %}

{% trans "Description:" %}

@@ -27,8 +23,3 @@ {% endif %}

{% endblock %} - -{% block modal-footer %} - - {% trans "Cancel" %} -{% endblock %} diff --git a/openstack_dashboard/dashboards/project/images/templates/images/images/_update.html b/openstack_dashboard/dashboards/project/images/templates/images/images/_update.html index 788ff56c7d..53099f8749 100644 --- a/openstack_dashboard/dashboards/project/images/templates/images/images/_update.html +++ b/openstack_dashboard/dashboards/project/images/templates/images/images/_update.html @@ -1,18 +1,7 @@ {% extends "horizon/common/_modal_form.html" %} {% load i18n %} -{% load url from future %} - -{% block form_id %}update_image_form{% endblock %} -{% block form_action %}{% url 'horizon:project:images:images:update' image.id %}{% endblock %} - -{% block modal-header %}{% trans "Update Image" %}{% endblock %} {% block modal-body-right %}

{% trans "Description:" %}

{% trans "Edit the image details." %}

{% endblock %} - -{% block modal-footer %} - - {% trans "Cancel" %} -{% endblock %} diff --git a/openstack_dashboard/dashboards/project/images/templates/images/snapshots/_create.html b/openstack_dashboard/dashboards/project/images/templates/images/snapshots/_create.html index 778f2f0900..e8a4be5896 100644 --- a/openstack_dashboard/dashboards/project/images/templates/images/snapshots/_create.html +++ b/openstack_dashboard/dashboards/project/images/templates/images/snapshots/_create.html @@ -1,26 +1,7 @@ {% extends "horizon/common/_modal_form.html" %} {% load i18n %} -{% load url from future %} -{% block form_id %}create_snapshot_form{% endblock %} -{% block form_action %}{% url 'horizon:project:images:snapshots:create' instance.id %}{% endblock %} - -{% block modal_id %}create_snapshot_modal{% endblock %} -{% block modal-header %}{% trans "Create Snapshot" %}{% endblock %} - -{% block modal-body %} -
-
- {% include "horizon/common/_form_fields.html" %} -
-
-
-

{% trans "Description:" %}

-

{% trans "A snapshot is an image which preserves the disk state of a running instance." %}

-
-{% endblock %} - -{% block modal-footer %} - - {% trans "Cancel" %} +{% block modal-body-right %} +

{% trans "Description:" %}

+

{% trans "A snapshot is an image which preserves the disk state of a running instance." %}

{% endblock %}