From 6740e10590951d89472e25e417406e13c40d5f0f Mon Sep 17 00:00:00 2001 From: Rob Cresswell Date: Mon, 23 Feb 2015 12:56:07 +0000 Subject: [PATCH] Refactor modal forms for Access & Security Refactor of Access & Security modals Based on merged patch: https://review.openstack.org/#/c/123472/ Change-Id: Ib8383fc478268309a52210c9923697315f5300d9 Partially-Implements: blueprint form-template-to-view --- .../access_and_security/floating_ips/views.py | 5 +++ .../access_and_security/keypairs/views.py | 10 +++++ .../security_groups/views.py | 20 ++++++++++ .../floating_ips/_allocate.html | 39 ++++++------------- .../access_and_security/keypairs/_create.html | 26 ++----------- .../access_and_security/keypairs/_import.html | 36 +++++------------ .../security_groups/_add_rule.html | 31 +++------------ .../security_groups/_create.html | 25 ++---------- .../security_groups/_update.html | 25 ++---------- 9 files changed, 71 insertions(+), 146 deletions(-) diff --git a/openstack_dashboard/dashboards/project/access_and_security/floating_ips/views.py b/openstack_dashboard/dashboards/project/access_and_security/floating_ips/views.py index 281d51031e..943d14d80b 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/floating_ips/views.py +++ b/openstack_dashboard/dashboards/project/access_and_security/floating_ips/views.py @@ -45,7 +45,12 @@ class AssociateView(workflows.WorkflowView): class AllocateView(forms.ModalFormView): form_class = project_forms.FloatingIpAllocate + form_id = "associate_floating_ip_form" + modal_header = _("Allocate Floating IP") template_name = 'project/access_and_security/floating_ips/allocate.html' + submit_label = _("Allocate IP") + submit_url = reverse_lazy( + "horizon:project:access_and_security:floating_ips:allocate") success_url = reverse_lazy('horizon:project:access_and_security:index') def get_object_display(self, obj): diff --git a/openstack_dashboard/dashboards/project/access_and_security/keypairs/views.py b/openstack_dashboard/dashboards/project/access_and_security/keypairs/views.py index 3361199d25..2489a923ef 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/keypairs/views.py +++ b/openstack_dashboard/dashboards/project/access_and_security/keypairs/views.py @@ -39,7 +39,12 @@ from openstack_dashboard.dashboards.project.access_and_security.keypairs \ class CreateView(forms.ModalFormView): form_class = project_forms.CreateKeypair + form_id = "create_keypair_form" + modal_header = _("Create Key Pair") template_name = 'project/access_and_security/keypairs/create.html' + submit_label = _("Create Key Pair") + submit_url = reverse_lazy( + "horizon:project:access_and_security:keypairs:create") success_url = 'horizon:project:access_and_security:keypairs:download' page_title = _("Create Key Pair") @@ -50,7 +55,12 @@ class CreateView(forms.ModalFormView): class ImportView(forms.ModalFormView): form_class = project_forms.ImportKeypair + form_id = "import_keypair_form" + modal_header = _("Import Key Pair") template_name = 'project/access_and_security/keypairs/import.html' + submit_label = _("Import Key Pair") + submit_url = reverse_lazy( + "horizon:project:access_and_security:keypairs:import") success_url = reverse_lazy('horizon:project:access_and_security:index') page_title = _("Import Key Pair") diff --git a/openstack_dashboard/dashboards/project/access_and_security/security_groups/views.py b/openstack_dashboard/dashboards/project/access_and_security/security_groups/views.py index 6bf2e6bd7f..00f921fee4 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/security_groups/views.py +++ b/openstack_dashboard/dashboards/project/access_and_security/security_groups/views.py @@ -69,7 +69,12 @@ class DetailView(tables.DataTableView): class UpdateView(forms.ModalFormView): form_class = project_forms.UpdateGroup + form_id = "update_security_group_form" + modal_header = _("Edit Security Group") + modal_id = "update_security_group_modal" template_name = 'project/access_and_security/security_groups/update.html' + submit_label = _("Edit Security Group") + submit_url = "horizon:project:access_and_security:security_groups:update" success_url = reverse_lazy('horizon:project:access_and_security:index') page_title = _("Edit Security Group") @@ -86,6 +91,8 @@ class UpdateView(forms.ModalFormView): def get_context_data(self, **kwargs): context = super(UpdateView, self).get_context_data(**kwargs) context["security_group"] = self.get_object() + args = (self.kwargs['security_group_id'],) + context['submit_url'] = reverse(self.submit_url, args=args) return context def get_initial(self): @@ -97,7 +104,12 @@ class UpdateView(forms.ModalFormView): class AddRuleView(forms.ModalFormView): form_class = project_forms.AddRule + form_id = "create_security_group_rule_form" + modal_header = _("Add Rule") + modal_id = "create_security_group_rule_modal" template_name = 'project/access_and_security/security_groups/add_rule.html' + submit_label = _("Add") + submit_url = "horizon:project:access_and_security:security_groups:add_rule" page_title = _("Add Rule") def get_success_url(self): @@ -108,6 +120,8 @@ class AddRuleView(forms.ModalFormView): def get_context_data(self, **kwargs): context = super(AddRuleView, self).get_context_data(**kwargs) context["security_group_id"] = self.kwargs['security_group_id'] + args = (self.kwargs['security_group_id'],) + context['submit_url'] = reverse(self.submit_url, args=args) return context def get_initial(self): @@ -137,6 +151,12 @@ class AddRuleView(forms.ModalFormView): class CreateView(forms.ModalFormView): form_class = project_forms.CreateGroup + form_id = "create_security_group_form" + modal_header = _("Create Security Group") + modal_id = "create_security_group_modal" template_name = 'project/access_and_security/security_groups/create.html' + submit_label = _("Create Security Group") + submit_url = reverse_lazy( + "horizon:project:access_and_security:security_groups:create") success_url = reverse_lazy('horizon:project:access_and_security:index') page_title = _("Create Security Group") diff --git a/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/floating_ips/_allocate.html b/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/floating_ips/_allocate.html index 3c3b02b82c..e47dd01d86 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/floating_ips/_allocate.html +++ b/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/floating_ips/_allocate.html @@ -1,30 +1,18 @@ {% extends "horizon/common/_modal_form.html" %} - {% load horizon i18n %} -{% load url from future %} -{% block form_id %}associate_floating_ip_form{% endblock %} -{% block form_action %}{% url 'horizon:project:access_and_security:floating_ips:allocate' %}{% endblock %} +{% block modal-body-right %} +
+

{% trans "Description:" %}

+

{% trans "Allocate a floating IP from a given floating IP pool." %}

-{% block modal-header %}{% trans "Allocate Floating IP" %}{% endblock %} - -{% block modal-body %} -
-
- {% include "horizon/common/_form_fields.html" %} -
-
-
-

{% trans "Description:" %}

-

{% trans "Allocate a floating IP from a given floating IP pool." %}

- -

{% trans "Project Quotas" %}

-
- {% trans "Floating IP" %} ({{ usages.floating_ips.used }}) -

{{ usages.floating_ips.available|quota }}

-
-
-
+

{% trans "Project Quotas" %}

+
+ {% trans "Floating IP" %} ({{ usages.floating_ips.used }}) +

{{ usages.floating_ips.available|quota }}

+
+
+
{% endblock %} - -{% block modal-footer %} - - {% trans "Cancel" %} -{% endblock %} diff --git a/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/keypairs/_create.html b/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/keypairs/_create.html index 134c36c348..b777a21823 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/keypairs/_create.html +++ b/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/keypairs/_create.html @@ -1,26 +1,8 @@ {% extends "horizon/common/_modal_form.html" %} {% load i18n %} -{% load url from future %} -{% block form_id %}create_keypair_form{% endblock %} -{% block form_action %}{% url 'horizon:project:access_and_security:keypairs:create' %}{% endblock %} - -{% block modal-header %}{% trans "Create Key Pair" %}{% endblock %} - -{% block modal-body %} -
-
- {% include "horizon/common/_form_fields.html" %} -
-
-
-

{% trans "Description:" %}

-

{% trans "Key pairs are ssh credentials which are injected into images when they are launched. Creating a new key pair registers the public key and downloads the private key (a .pem file)." %}

-

{% trans "Protect and use the key as you would any normal ssh private key." %}

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

{% trans "Description:" %}

+

{% trans "Key pairs are ssh credentials which are injected into images when they are launched. Creating a new key pair registers the public key and downloads the private key (a .pem file)." %}

+

{% trans "Protect and use the key as you would any normal ssh private key." %}

{% endblock %} diff --git a/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/keypairs/_import.html b/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/keypairs/_import.html index 10c82f6f1a..a247df76aa 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/keypairs/_import.html +++ b/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/keypairs/_import.html @@ -1,31 +1,13 @@ {% extends "horizon/common/_modal_form.html" %} {% load i18n %} -{% load url from future %} -{% block form_id %}import_keypair_form{% endblock %} -{% block form_action %}{% url 'horizon:project:access_and_security:keypairs:import' %}{% endblock %} - -{% block modal-header %}{% trans "Import Key Pair" %}{% endblock %} - -{% block modal-body %} -
-
- {% include "horizon/common/_form_fields.html" %} -
-
-
-

{% trans "Description:" %}

-

{% trans "Key Pairs are how you login to your instance after it is launched." %}

-

{% trans "Choose a key pair name you will recognise and paste your SSH public key into the space provided." %}

-

{% trans "SSH key pairs can be generated with the ssh-keygen command:" %}

-

ssh-keygen -t rsa -f cloud.key

-

{% trans "This generates a pair of keys: a key you keep private (cloud.key) and a public key (cloud.key.pub). Paste the contents of the public key file here." %}

-

{% trans "After launching an instance, you login using the private key (the username might be different depending on the image you launched):" %}

-

ssh -i cloud.key <username>@<instance_ip>

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

{% trans "Description:" %}

+

{% trans "Key Pairs are how you login to your instance after it is launched." %}

+

{% trans "Choose a key pair name you will recognise and paste your SSH public key into the space provided." %}

+

{% trans "SSH key pairs can be generated with the ssh-keygen command:" %}

+

ssh-keygen -t rsa -f cloud.key

+

{% trans "This generates a pair of keys: a key you keep private (cloud.key) and a public key (cloud.key.pub). Paste the contents of the public key file here." %}

+

{% trans "After launching an instance, you login using the private key (the username might be different depending on the image you launched):" %}

+

ssh -i cloud.key <username>@<instance_ip>

{% endblock %} diff --git a/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/security_groups/_add_rule.html b/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/security_groups/_add_rule.html index 637ee32757..5c29163b5f 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/security_groups/_add_rule.html +++ b/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/security_groups/_add_rule.html @@ -1,29 +1,10 @@ {% extends "horizon/common/_modal_form.html" %} {% load i18n %} -{% load url from future %} -{% block form_id %}create_security_group_rule_form{% endblock %} -{% block form_action %}{% url 'horizon:project:access_and_security:security_groups:add_rule' security_group_id %}{% endblock %} - -{% block modal-header %}{% trans "Add Rule" %}{% endblock %} -{% block modal_id %}create_security_group_rule_modal{% endblock %} - -{% block modal-body %} -
-
- {% include "horizon/common/_form_fields.html" %} -
-
-
-

{% trans "Description:" %}

-

{% blocktrans %}Rules define which traffic is allowed to instances assigned to the security group. A security group rule consists of three main parts:{% endblocktrans %}

-

{% trans "Rule:" %} {% blocktrans %}You can specify the desired rule template or use custom rules, the options are Custom TCP Rule, Custom UDP Rule, or Custom ICMP Rule.{% endblocktrans %}

-

{% trans "Open Port/Port Range:" %} {% blocktrans %}For TCP and UDP rules you may choose to open either a single port or a range of ports. Selecting the "Port Range" option will provide you with space to provide both the starting and ending ports for the range. For ICMP rules you instead specify an ICMP type and code in the spaces provided.{% endblocktrans %}

-

{% trans "Remote:" %} {% blocktrans %}You must specify the source of the traffic to be allowed via this rule. You may do so either in the form of an IP address block (CIDR) or via a source group (Security Group). Selecting a security group as the source will allow any other instance in that security group access to any other instance via this rule.{% endblocktrans %}

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

{% trans "Description:" %}

+

{% blocktrans %}Rules define which traffic is allowed to instances assigned to the security group. A security group rule consists of three main parts:{% endblocktrans %}

+

{% trans "Rule:" %} {% blocktrans %}You can specify the desired rule template or use custom rules, the options are Custom TCP Rule, Custom UDP Rule, or Custom ICMP Rule.{% endblocktrans %}

+

{% trans "Open Port/Port Range:" %} {% blocktrans %}For TCP and UDP rules you may choose to open either a single port or a range of ports. Selecting the "Port Range" option will provide you with space to provide both the starting and ending ports for the range. For ICMP rules you instead specify an ICMP type and code in the spaces provided.{% endblocktrans %}

+

{% trans "Remote:" %} {% blocktrans %}You must specify the source of the traffic to be allowed via this rule. You may do so either in the form of an IP address block (CIDR) or via a source group (Security Group). Selecting a security group as the source will allow any other instance in that security group access to any other instance via this rule.{% endblocktrans %}

{% endblock %} diff --git a/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/security_groups/_create.html b/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/security_groups/_create.html index 73483c602b..655cebaf13 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/security_groups/_create.html +++ b/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/security_groups/_create.html @@ -1,26 +1,7 @@ {% extends "horizon/common/_modal_form.html" %} {% load i18n %} -{% load url from future %} -{% block form_id %}create_security_group_form{% endblock %} -{% block form_action %}{% url 'horizon:project:access_and_security:security_groups:create' %}{% endblock %} - -{% block modal-header %}{% trans "Create Security Group" %}{% endblock %} -{% block modal_id %}create_security_group_modal{% endblock %} - -{% block modal-body %} -
-
- {% include "horizon/common/_form_fields.html" %} -
-
-
-

{% trans "Description:" %}

-

{% trans "Security groups are sets of IP filter rules that are applied to the network settings for the VM. After the security group is created, you can add rules to the security group." %}

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

{% trans "Description:" %}

+

{% trans "Security groups are sets of IP filter rules that are applied to the network settings for the VM. After the security group is created, you can add rules to the security group." %}

{% endblock %} diff --git a/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/security_groups/_update.html b/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/security_groups/_update.html index da5309d222..d94ea7339a 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/security_groups/_update.html +++ b/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/security_groups/_update.html @@ -1,26 +1,7 @@ {% extends "horizon/common/_modal_form.html" %} {% load i18n %} -{% load url from future %} -{% block form_id %}update_security_group_form{% endblock %} -{% block form_action %}{% url 'horizon:project:access_and_security:security_groups:update' security_group.id %}{% endblock %} - -{% block modal-header %}{% trans "Edit Security Group" %}{% endblock %} -{% block modal_id %}update_security_group_modal{% endblock %} - -{% block modal-body %} -
-
- {% include "horizon/common/_form_fields.html" %} -
-
-
-

{% trans "Description:" %}

-

{% trans "Security groups are sets of IP filter rules that are applied to the network settings for the VM. Edit the security group to add and change the rules." %}

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

{% trans "Description:" %}

+

{% trans "Security groups are sets of IP filter rules that are applied to the network settings for the VM. Edit the security group to add and change the rules." %}

{% endblock %}