Bug 1126674 - [RFE][horizon]: Move form templating logic to the ModalFormView
Summary: [RFE][horizon]: Move form templating logic to the ModalFormView
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Red Hat OpenStack
Classification: Red Hat
Component: RFEs
Version: unspecified
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: ---
: ---
Assignee: RHOS Maint
QA Contact:
URL: https://blueprints.launchpad.net/hori...
Whiteboard: upstream_milestone_none upstream_defi...
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-08-05 04:04 UTC by RHOS Integration
Modified: 2015-03-19 16:57 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Enhancement
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-03-19 16:57:24 UTC


Attachments (Terms of Use)

Description RHOS Integration 2014-08-05 04:04:33 UTC
Cloned from launchpad blueprint https://blueprints.launchpad.net/horizon/+spec/form-template-to-view.

Description:

Below is a typical form:

{% extends "horizon/common/_modal_form.html" %}
{% load i18n %}
{% load url from future %}
{% block form_id %}update_role_form{% endblock %}
{% block form_action %}{% url 'horizon:admin: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 "From here you can edit the role's details." %}</p>
</div>
{% endblock %}
{% block modal-footer %}
  <a href="{% url 'horizon:admin:roles:index' %}" class="btn btn-default cancel">{% trans "Cancel" %}</a>
  <input class="btn btn-primary" type="submit" value="{% trans "Update Role" %}"/>
{% endblock %}

----------------------------------------------------------------------------------------------------------------------------------------------------
In a typical form, many variables such as id, action_url, success_url, cancel button, submit button are repeated. Currently, we are redefining these variables by overriding them using blocks. It is much cleaner to define these variables in python, and let the base modal_form.html populate them. That way, most of our logic is in one place and we would also reduce the clutter in the templates.

In addition, the left and right part of the modal is consistently use. It make sense for us to make that the default template, and let users override the right part while keeping the left. But we also need to retain the ability to override entire thing if required. Something like this should suffice:

<div class="modal-body clearfix">
  {% block modal-body %}
 <div class="left">
   <fieldset>{% include "horizon/common/_form_fields.html" %}</fieldset>
 </div>
 <div class="right">
   {% block modal-body-right %}{% endblock %}
 </div>
  {% endblock %}
</div>

----------------------------------------------------------------------------------------------------------------------------------------------------
So what exactly am I proposing?

class ModalFormView:
  id - the unique identifier of this form
  name - the header of this form
  action_url - the url to trigger the confirm action
  success_url - the url to redirect for cancel action and success
  confirm_label - the label for the confirm button
  cancel_label - the label for the cancel button

Now a typical form can look like:

{% extends "horizon/common/_modal_form.html" %}
{% load i18n %}
{% load url from future %}
{% block modal-body-right %}
    <h3>{% trans "Description" %}:</h3>
    <p>{% trans "From here you can edit the role's details." %}</p>
{% endblock %}

Specification URL (additional information):

None


Note You need to log in before you can comment on or make changes to this bug.