Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #12878. Formset-wide errors are now rendered properly as html.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12548 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ea3853e8d294deebe47d7845b332bef5dbe5f03e 1 parent c8fa110
@jkocherhans jkocherhans authored
View
2  django/forms/formsets.py
@@ -271,7 +271,7 @@ def full_clean(self):
try:
self.clean()
except ValidationError, e:
- self._non_form_errors = e.messages
+ self._non_form_errors = self.error_class(e.messages)
def clean(self):
"""
View
17 tests/regressiontests/admin_views/tests.py
@@ -11,6 +11,7 @@
from django.contrib.admin.sites import LOGIN_FORM_KEY
from django.contrib.admin.util import quote
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
+from django.forms.util import ErrorList
from django.utils import formats
from django.utils.cache import get_max_age
from django.utils.html import escape
@@ -1028,6 +1029,22 @@ def test_non_form_errors(self):
response = self.client.post('/test_admin/admin/admin_views/person/', data)
self.assertContains(response, "Grace is not a Zombie")
+ def test_non_form_errors_is_errorlist(self):
+ # test if non-form errors are correctly handled; ticket #12878
+ data = {
+ "form-TOTAL_FORMS": "1",
+ "form-INITIAL_FORMS": "1",
+ "form-MAX_NUM_FORMS": "0",
+
+ "form-0-id": "2",
+ "form-0-alive": "1",
+ "form-0-gender": "2",
+ }
+ response = self.client.post('/test_admin/admin/admin_views/person/', data)
+ non_form_errors = response.context['cl'].formset.non_form_errors()
+ self.assert_(isinstance(non_form_errors, ErrorList))
+ self.assertEqual(str(non_form_errors), str(ErrorList(["Grace is not a Zombie"])))
+
def test_list_editable_ordering(self):
collector = Collector.objects.create(id=1, name="Frederick Clegg")
View
16 tests/regressiontests/forms/formsets.py
@@ -621,4 +621,20 @@
>>> formset.management_form.prefix
'form'
+# Regression test for #12878 #################################################
+
+>>> data = {
+... 'drinks-TOTAL_FORMS': '2', # the number of forms rendered
+... 'drinks-INITIAL_FORMS': '0', # the number of forms with initial data
+... 'drinks-MAX_NUM_FORMS': '0', # max number of forms
+... 'drinks-0-name': 'Gin and Tonic',
+... 'drinks-1-name': 'Gin and Tonic',
+... }
+
+>>> formset = FavoriteDrinksFormSet(data, prefix='drinks')
+>>> formset.is_valid()
+False
+>>> print formset.non_form_errors()
+<ul class="errorlist"><li>You may only specify a drink once.</li></ul>
+
"""
Please sign in to comment.
Something went wrong with that request. Please try again.