Clean modal forms in Identity Roles

Refactoring identity roles modals.
Based on merged patch: https://review.openstack.org/#/c/123472/

Change-Id: I435b10456e1a400888cc7aaa3af879543bbff950
Partially-Implements: blueprint form-template-to-view
Partially-Closes-Bug: #1350953
This commit is contained in:
Thai Tran 2014-12-11 18:03:13 -08:00
parent 4a0f781610
commit 2adfd0d2a1
3 changed files with 19 additions and 46 deletions

View File

@ -1,25 +1,7 @@
{% extends "horizon/common/_modal_form.html" %}
{% load i18n %}
{% load url from future %}
{% block form_id %}create_role_form{% endblock %}
{% block form_action %}{% url 'horizon:identity:roles:create' %}{% endblock %}
{% block modal-header %}{% trans "Create Role" %}{% 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 "Create a new role." %}</p>
</div>
{% endblock %}
{% block modal-footer %}
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Create Role" %}" />
<a href="{% url 'horizon:identity:roles:index' %}" class="btn btn-default secondary cancel close">{% trans "Cancel" %}</a>
{% endblock %}
{% block modal-body-right %}
<h3>{% trans "Description:" %}</h3>
<p>{% trans "Create a new role." %}</p>
{% endblock %}

View File

@ -1,25 +1,7 @@
{% extends "horizon/common/_modal_form.html" %}
{% load i18n %}
{% load url from future %}
{% block form_id %}update_role_form{% endblock %}
{% block form_action %}{% url 'horizon:identity:roles:update' role.id %}{% endblock %}
{% block modal-header %}{% trans "Update Role" %}{% 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 "Edit the role's details." %}</p>
</div>
{% endblock %}
{% block modal-footer %}
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Update Role" %}" />
<a href="{% url 'horizon:identity:roles:index' %}" class="btn btn-default secondary cancel close">{% trans "Cancel" %}</a>
{% block modal-body-right %}
<h3>{% trans "Description:" %}</h3>
<p>{% trans "Edit the role's details." %}</p>
{% endblock %}

View File

@ -51,8 +51,12 @@ class IndexView(tables.DataTableView):
class UpdateView(forms.ModalFormView):
form_class = project_forms.UpdateRoleForm
template_name = 'identity/roles/update.html'
modal_header = _("Update Role")
form_id = "update_role_form"
form_class = project_forms.UpdateRoleForm
submit_label = _("Update Role")
submit_url = "horizon:identity:roles:update"
success_url = reverse_lazy('horizon:identity:roles:index')
@memoized.memoized_method
@ -67,7 +71,8 @@ class UpdateView(forms.ModalFormView):
def get_context_data(self, **kwargs):
context = super(UpdateView, self).get_context_data(**kwargs)
context['role'] = self.get_object()
args = (self.get_object().id,)
context['submit_url'] = reverse(self.submit_url, args=args)
return context
def get_initial(self):
@ -77,6 +82,10 @@ class UpdateView(forms.ModalFormView):
class CreateView(forms.ModalFormView):
form_class = project_forms.CreateRoleForm
template_name = 'identity/roles/create.html'
modal_header = _("Create Role")
form_id = "create_role_form"
form_class = project_forms.CreateRoleForm
submit_label = _("Create Role")
submit_url = reverse_lazy("horizon:identity:roles:create")
success_url = reverse_lazy('horizon:identity:roles:index')