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
This commit is contained in:
Rob Cresswell 2015-02-23 12:56:07 +00:00
parent bf7e106d7f
commit 6740e10590
9 changed files with 71 additions and 146 deletions

View File

@ -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):

View File

@ -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")

View File

@ -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")

View File

@ -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 %}
<div class="quota-dynamic">
<h3>{% trans "Description:" %}</h3>
<p>{% trans "Allocate a floating IP from a given floating IP pool." %}</p>
{% block modal-header %}{% trans "Allocate Floating IP" %}{% endblock %}
{% block modal-body %}
<div class="left">
<fieldset>
{% include "horizon/common/_form_fields.html" %}
</fieldset>
</div>
<div class="right quota-dynamic">
<h3>{% trans "Description:" %}</h3>
<p>{% trans "Allocate a floating IP from a given floating IP pool." %}</p>
<h3>{% trans "Project Quotas" %}</h3>
<div class="quota_title">
<strong>{% trans "Floating IP" %} <span>({{ usages.floating_ips.used }})</span></strong>
<p>{{ usages.floating_ips.available|quota }}</p>
</div>
<div class="clearfix"></div>
<div id="floating_ip_progress" class="quota_bar" data-quota-used="{{ usages.floating_ips.used }}" data-quota-limit="{{ usages.floating_ips.quota }}" data-progress-indicator-step-by="1"></div>
<h3>{% trans "Project Quotas" %}</h3>
<div class="quota_title">
<strong>{% trans "Floating IP" %} <span>({{ usages.floating_ips.used }})</span></strong>
<p>{{ usages.floating_ips.available|quota }}</p>
</div>
<div class="clearfix"></div>
<div id="floating_ip_progress" class="quota_bar" data-quota-used="{{ usages.floating_ips.used }}" data-quota-limit="{{ usages.floating_ips.quota }}" data-progress-indicator-step-by="1"></div>
</div>
<script type="text/javascript" charset="utf-8">
@ -37,8 +25,3 @@
}
</script>
{% endblock %}
{% block modal-footer %}
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Allocate IP" %}" />
<a href="{% url 'horizon:project:access_and_security:index' %}" class="btn btn-default secondary cancel close">{% trans "Cancel" %}</a>
{% endblock %}

View File

@ -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 %}
<div class="left">
<fieldset>
{% include "horizon/common/_form_fields.html" %}
</fieldset>
</div>
<div class="right">
<h3>{% trans "Description:" %}</h3>
<p>{% 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)." %}</p>
<p>{% trans "Protect and use the key as you would any normal ssh private key." %}</p>
</div>
{% endblock %}
{% block modal-footer %}
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Create Key Pair" %}" />
<a href="{% url 'horizon:project:access_and_security:index' %}" class="btn btn-default secondary cancel close">{% trans "Cancel" %}</a>
{% block modal-body-right %}
<h3>{% trans "Description:" %}</h3>
<p>{% 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)." %}</p>
<p>{% trans "Protect and use the key as you would any normal ssh private key." %}</p>
{% endblock %}

View File

@ -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 %}
<div class="left">
<fieldset>
{% include "horizon/common/_form_fields.html" %}
</fieldset>
</div>
<div class="right">
<h3>{% trans "Description:" %}</h3>
<p>{% trans "Key Pairs are how you login to your instance after it is launched." %}</p>
<p>{% trans "Choose a key pair name you will recognise and paste your SSH public key into the space provided." %}</p>
<p>{% trans "SSH key pairs can be generated with the ssh-keygen command:" %}</p>
<p><pre>ssh-keygen -t rsa -f cloud.key</pre></p>
<p>{% 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." %}</p>
<p>{% trans "After launching an instance, you login using the private key (the username might be different depending on the image you launched):" %}</p>
<p><pre>ssh -i cloud.key &lt;username&gt;@&lt;instance_ip&gt;</pre></p>
</div>
{% endblock %}
{% block modal-footer %}
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Import Key Pair" %}" />
<a href="{% url 'horizon:project:access_and_security:index' %}" class="btn btn-default secondary cancel close">{% trans "Cancel" %}</a>
{% block modal-body-right %}
<h3>{% trans "Description:" %}</h3>
<p>{% trans "Key Pairs are how you login to your instance after it is launched." %}</p>
<p>{% trans "Choose a key pair name you will recognise and paste your SSH public key into the space provided." %}</p>
<p>{% trans "SSH key pairs can be generated with the ssh-keygen command:" %}</p>
<p><pre>ssh-keygen -t rsa -f cloud.key</pre></p>
<p>{% 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." %}</p>
<p>{% trans "After launching an instance, you login using the private key (the username might be different depending on the image you launched):" %}</p>
<p><pre>ssh -i cloud.key &lt;username&gt;@&lt;instance_ip&gt;</pre></p>
{% endblock %}

View File

@ -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 %}
<div class="left">
<fieldset>
{% include "horizon/common/_form_fields.html" %}
</fieldset>
</div>
<div class="right">
<h3>{% trans "Description:" %}</h3>
<p>{% blocktrans %}Rules define which traffic is allowed to instances assigned to the security group. A security group rule consists of three main parts:{% endblocktrans %}</p>
<p><strong>{% trans "Rule:" %}</strong> {% 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 %}</p>
<p><strong>{% trans "Open Port/Port Range:" %}</strong> {% 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 %}</p>
<p><strong>{% trans "Remote:" %}</strong> {% 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 %}</p>
</div>
{% endblock %}
{% block modal-footer %}
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Add" %}" />
<a href="{% url 'horizon:project:access_and_security:security_groups:detail' security_group_id %}" class="btn btn-default secondary cancel close">{% trans "Cancel" %}</a>
{% block modal-body-right %}
<h3>{% trans "Description:" %}</h3>
<p>{% blocktrans %}Rules define which traffic is allowed to instances assigned to the security group. A security group rule consists of three main parts:{% endblocktrans %}</p>
<p><strong>{% trans "Rule:" %}</strong> {% 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 %}</p>
<p><strong>{% trans "Open Port/Port Range:" %}</strong> {% 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 %}</p>
<p><strong>{% trans "Remote:" %}</strong> {% 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 %}</p>
{% endblock %}

View File

@ -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 %}
<div class="left">
<fieldset>
{% include "horizon/common/_form_fields.html" %}
</fieldset>
</div>
<div class="right">
<h3>{% trans "Description:" %}</h3>
<p>{% 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." %}</p>
</div>
{% endblock %}
{% block modal-footer %}
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Create Security Group" %}" />
<a href="{% url 'horizon:project:access_and_security:index' %}" class="btn btn-default secondary cancel close">{% trans "Cancel" %}</a>
{% block modal-body-right %}
<h3>{% trans "Description:" %}</h3>
<p>{% 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." %}</p>
{% endblock %}

View File

@ -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 %}
<div class="left">
<fieldset>
{% include "horizon/common/_form_fields.html" %}
</fieldset>
</div>
<div class="right">
<h3>{% trans "Description:" %}</h3>
<p>{% 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." %}</p>
</div>
{% endblock %}
{% block modal-footer %}
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Edit Security Group" %}" />
<a href="{% url 'horizon:project:access_and_security:index' %}" class="btn btn-default secondary cancel close">{% trans "Cancel" %}</a>
{% block modal-body-right %}
<h3>{% trans "Description:" %}</h3>
<p>{% 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." %}</p>
{% endblock %}