Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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 authored February 23, 2010
2  django/forms/formsets.py
@@ -252,7 +252,7 @@ def full_clean(self):
252 252
         try:
253 253
             self.clean()
254 254
         except ValidationError, e:
255  
-            self._non_form_errors = e.messages
  255
+            self._non_form_errors = self.error_class(e.messages)
256 256
 
257 257
     def clean(self):
258 258
         """
17  tests/regressiontests/admin_views/tests.py
@@ -10,6 +10,7 @@
10 10
 from django.contrib.admin.sites import LOGIN_FORM_KEY
11 11
 from django.contrib.admin.util import quote
12 12
 from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
  13
+from django.forms.util import ErrorList
13 14
 from django.utils.cache import get_max_age
14 15
 from django.utils.html import escape
15 16
 
@@ -966,6 +967,22 @@ def test_non_form_errors(self):
966 967
         response = self.client.post('/test_admin/admin/admin_views/person/', data)
967 968
         self.assertContains(response, "Grace is not a Zombie")
968 969
 
  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
+
969 986
     def test_list_editable_ordering(self):
970 987
         collector = Collector.objects.create(id=1, name="Frederick Clegg")
971 988
 
16  tests/regressiontests/forms/formsets.py
@@ -598,4 +598,20 @@
598 598
 >>> formset.management_form.prefix
599 599
 'form'
600 600
 
  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
+
601 617
 """

0 notes on commit 860497c

Please sign in to comment.
Something went wrong with that request. Please try again.