Skip to content

Commit 860497c

Browse files
committed
[1.1.x] Fixed #12878. Formset-wide errors are now rendered properly as 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
1 parent a1bff5f commit 860497c

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

django/forms/formsets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def full_clean(self):
252252
try:
253253
self.clean()
254254
except ValidationError, e:
255-
self._non_form_errors = e.messages
255+
self._non_form_errors = self.error_class(e.messages)
256256

257257
def clean(self):
258258
"""

tests/regressiontests/admin_views/tests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from django.contrib.admin.sites import LOGIN_FORM_KEY
1111
from django.contrib.admin.util import quote
1212
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
13+
from django.forms.util import ErrorList
1314
from django.utils.cache import get_max_age
1415
from django.utils.html import escape
1516

@@ -966,6 +967,22 @@ def test_non_form_errors(self):
966967
response = self.client.post('/test_admin/admin/admin_views/person/', data)
967968
self.assertContains(response, "Grace is not a Zombie")
968969

970+
def test_non_form_errors_is_errorlist(self):
971+
# test if non-form errors are correctly handled; ticket #12878
972+
data = {
973+
"form-TOTAL_FORMS": "1",
974+
"form-INITIAL_FORMS": "1",
975+
"form-MAX_NUM_FORMS": "0",
976+
977+
"form-0-id": "2",
978+
"form-0-alive": "1",
979+
"form-0-gender": "2",
980+
}
981+
response = self.client.post('/test_admin/admin/admin_views/person/', data)
982+
non_form_errors = response.context['cl'].formset.non_form_errors()
983+
self.assert_(isinstance(non_form_errors, ErrorList))
984+
self.assertEqual(str(non_form_errors), str(ErrorList(["Grace is not a Zombie"])))
985+
969986
def test_list_editable_ordering(self):
970987
collector = Collector.objects.create(id=1, name="Frederick Clegg")
971988

tests/regressiontests/forms/formsets.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,4 +598,20 @@
598598
>>> formset.management_form.prefix
599599
'form'
600600
601+
# Regression test for #12878 #################################################
602+
603+
>>> data = {
604+
... 'drinks-TOTAL_FORMS': '2', # the number of forms rendered
605+
... 'drinks-INITIAL_FORMS': '0', # the number of forms with initial data
606+
... 'drinks-MAX_NUM_FORMS': '0', # max number of forms
607+
... 'drinks-0-name': 'Gin and Tonic',
608+
... 'drinks-1-name': 'Gin and Tonic',
609+
... }
610+
611+
>>> formset = FavoriteDrinksFormSet(data, prefix='drinks')
612+
>>> formset.is_valid()
613+
False
614+
>>> print formset.non_form_errors()
615+
<ul class="errorlist"><li>You may only specify a drink once.</li></ul>
616+
601617
"""

0 commit comments

Comments
 (0)