Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.1.x] Fixed #12878. Formset-wide errors are now rendered properly a…

…s html. Backport of r12548 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12549 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 860497c9b3f2f54ef71cb55b5b59dbb9f24dfccd 1 parent a1bff5f
Joseph Kocherhans jkocherhans authored
2  django/forms/formsets.py
View
@@ -252,7 +252,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):
"""
17 tests/regressiontests/admin_views/tests.py
View
@@ -10,6 +10,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.cache import get_max_age
from django.utils.html import escape
@@ -966,6 +967,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")
16 tests/regressiontests/forms/formsets.py
View
@@ -598,4 +598,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.