Preserve add-to-field after form error.
Fixes bug 1037302. Change-Id: I827f1b74efc6835dfac1fdcdc7c2a7c12af421eb
This commit is contained in:
parent
85b0bfe68e
commit
8756b3b2ad
@ -23,6 +23,9 @@ from horizon.openstack.common import jsonutils
|
|||||||
from horizon import exceptions
|
from horizon import exceptions
|
||||||
|
|
||||||
|
|
||||||
|
ADD_TO_FIELD_HEADER = "HTTP_X_HORIZON_ADD_TO_FIELD"
|
||||||
|
|
||||||
|
|
||||||
class ModalFormMixin(object):
|
class ModalFormMixin(object):
|
||||||
def get_template_names(self):
|
def get_template_names(self):
|
||||||
if self.request.is_ajax():
|
if self.request.is_ajax():
|
||||||
@ -40,6 +43,8 @@ class ModalFormMixin(object):
|
|||||||
context = super(ModalFormMixin, self).get_context_data(**kwargs)
|
context = super(ModalFormMixin, self).get_context_data(**kwargs)
|
||||||
if self.request.is_ajax():
|
if self.request.is_ajax():
|
||||||
context['hide'] = True
|
context['hide'] = True
|
||||||
|
if ADD_TO_FIELD_HEADER in self.request.META:
|
||||||
|
context['add_to_field'] = self.request.META[ADD_TO_FIELD_HEADER]
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
@ -64,8 +69,8 @@ class ModalFormView(ModalFormMixin, generic.FormView):
|
|||||||
exceptions.handle(self.request)
|
exceptions.handle(self.request)
|
||||||
|
|
||||||
if handled:
|
if handled:
|
||||||
if "HTTP_X_HORIZON_ADD_TO_FIELD" in self.request.META:
|
if ADD_TO_FIELD_HEADER in self.request.META:
|
||||||
field_id = self.request.META["HTTP_X_HORIZON_ADD_TO_FIELD"]
|
field_id = self.request.META[ADD_TO_FIELD_HEADER]
|
||||||
data = [self.get_object_id(handled),
|
data = [self.get_object_id(handled),
|
||||||
self.get_object_display(handled)]
|
self.get_object_display(handled)]
|
||||||
response = http.HttpResponse(jsonutils.dumps(data))
|
response = http.HttpResponse(jsonutils.dumps(data))
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<form id="{% block form_id %}{% endblock %}" class="{% block form_class %}{% endblock %}" action="{% block form_action %}{% endblock %}" method="{% block form-method %}POST{% endblock %}" {% block form_attrs %}{% endblock %}>{% csrf_token %}
|
<form id="{% block form_id %}{% endblock %}" class="{% block form_class %}{% endblock %}" action="{% block form_action %}{% endblock %}" method="{% block form-method %}POST{% endblock %}" {% if add_to_field %}data-add-to-field="{{ add_to_field }}"{% endif %} {% block form_attrs %}{% endblock %}>{% csrf_token %}
|
||||||
<div class="modal-body clearfix">
|
<div class="modal-body clearfix">
|
||||||
{% block modal-body %}
|
{% block modal-body %}
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% with workflow.get_entry_point as entry_point %}
|
{% with workflow.get_entry_point as entry_point %}
|
||||||
<div class="workflow {% if modal %}modal hide{% else %}static_page{% endif %}">
|
<div class="workflow {% if modal %}modal hide{% else %}static_page{% endif %}">
|
||||||
<form {{ workflow.attr_string|safe }} action="{{ workflow.get_absolute_url }}" method="POST">{% csrf_token %}
|
<form {{ workflow.attr_string|safe }} action="{{ workflow.get_absolute_url }}" {% if add_to_field %}data-add-to-field="{{ add_to_field }}"{% endif %} method="POST">{% csrf_token %}
|
||||||
{% if REDIRECT_URL %}<input type="hidden" name="{{ workflow.redirect_param_name }}" value="{{ REDIRECT_URL }}"/>{% endif %}
|
{% if REDIRECT_URL %}<input type="hidden" name="{{ workflow.redirect_param_name }}" value="{{ REDIRECT_URL }}"/>{% endif %}
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
{% if modal %}<a href="#" class="close" data-dismiss="modal">×</a>{% endif %}
|
{% if modal %}<a href="#" class="close" data-dismiss="modal">×</a>{% endif %}
|
||||||
|
@ -22,6 +22,7 @@ from django.views import generic
|
|||||||
|
|
||||||
from horizon import exceptions
|
from horizon import exceptions
|
||||||
from horizon import messages
|
from horizon import messages
|
||||||
|
from horizon.forms.views import ADD_TO_FIELD_HEADER
|
||||||
from horizon.openstack.common import jsonutils
|
from horizon.openstack.common import jsonutils
|
||||||
|
|
||||||
|
|
||||||
@ -93,6 +94,8 @@ class WorkflowView(generic.TemplateView):
|
|||||||
context['REDIRECT_URL'] = next
|
context['REDIRECT_URL'] = next
|
||||||
if self.request.is_ajax():
|
if self.request.is_ajax():
|
||||||
context['modal'] = True
|
context['modal'] = True
|
||||||
|
if ADD_TO_FIELD_HEADER in self.request.META:
|
||||||
|
context['add_to_field'] = self.request.META[ADD_TO_FIELD_HEADER]
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_template_names(self):
|
def get_template_names(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user