Ticket #12878: 12878-1.diff

File 12878-1.diff, 2.0 KB (added by matiasb, 15 years ago)

Fixed formsets to set non_form_errors as errorlist after a full_clean

  • django/forms/formsets.py

     
    271271        try:
    272272            self.clean()
    273273        except ValidationError, e:
    274             self._non_form_errors = e.messages
     274            self._non_form_errors = self.error_class(e.messages)
    275275
    276276    def clean(self):
    277277        """
  • tests/regressiontests/admin_views/tests.py

     
    1111from django.contrib.admin.sites import LOGIN_FORM_KEY
    1212from django.contrib.admin.util import quote
    1313from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
     14from django.forms.util import ErrorList
    1415from django.utils import formats
    1516from django.utils.cache import get_max_age
    1617from django.utils.html import escape
     
    10281029        response = self.client.post('/test_admin/admin/admin_views/person/', data)
    10291030        self.assertContains(response, "Grace is not a Zombie")
    10301031
     1032    def test_non_form_errors_is_errorlist(self):
     1033        # test if non-form errors are correctly handled; ticket #12878
     1034        data = {
     1035            "form-TOTAL_FORMS": "1",
     1036            "form-INITIAL_FORMS": "1",
     1037            "form-MAX_NUM_FORMS": "0",
     1038
     1039            "form-0-id": "2",
     1040            "form-0-alive": "1",
     1041            "form-0-gender": "2",
     1042        }
     1043        response = self.client.post('/test_admin/admin/admin_views/person/', data)
     1044        non_form_errors = response.context['cl'].formset.non_form_errors()
     1045        self.assert_(isinstance(non_form_errors, ErrorList))
     1046        self.assertEqual(str(non_form_errors), str(ErrorList(["Grace is not a Zombie"])))
     1047
    10311048    def test_list_editable_ordering(self):
    10321049        collector = Collector.objects.create(id=1, name="Frederick Clegg")
    10331050
Back to Top