Ticket #15167: 15167.diff
File 15167.diff, 2.9 KB (added by , 14 years ago) |
---|
-
django/forms/models.py
511 511 # poke error messages into the right places and mark 512 512 # the form as invalid 513 513 errors.append(self.get_unique_error_message(unique_check)) 514 form._errors[NON_FIELD_ERRORS] = self. get_form_error()514 form._errors[NON_FIELD_ERRORS] = self.error_class([self.get_form_error()]) 515 515 del form.cleaned_data 516 516 break 517 517 # mark the data as seen … … 542 542 # poke error messages into the right places and mark 543 543 # the form as invalid 544 544 errors.append(self.get_date_error_message(date_check)) 545 form._errors[NON_FIELD_ERRORS] = self. get_form_error()545 form._errors[NON_FIELD_ERRORS] = self.error_class([self.get_form_error()]) 546 546 del form.cleaned_data 547 547 break 548 548 seen_data.add(data) -
tests/regressiontests/model_formsets_regress/tests.py
1 1 from django import forms 2 from django.forms.util import ErrorDict, ErrorList 2 3 from django.forms.models import modelform_factory, inlineformset_factory, modelformset_factory 3 4 from django.test import TestCase 4 5 … … 200 201 ["<Host: matrix.de.eu.dal.net>", "<Host: tranquility.hub.dal.net>"] 201 202 ) 202 203 204 class FormsetTests(TestCase): 205 def test_error_class(self): 206 ''' 207 Test the type of Formset and Form error attributes 208 ''' 209 Formset = modelformset_factory(User) 210 data = { 211 'form-TOTAL_FORMS': u'2', 212 'form-INITIAL_FORMS': u'0', 213 'form-MAX_NUM_FORMS': u'0', 214 'form-0-id': '', 215 'form-0-username': u'apollo13', 216 'form-0-serial': u'1', 217 'form-1-id': '', 218 'form-1-username': u'apollo13', 219 'form-1-serial': u'2', 220 } 221 formset = Formset(data) 222 # check if the returned error classes are correct 223 # note: formset.errors returns a list as documented 224 self.assertTrue(isinstance(formset.errors, list)) 225 self.assertTrue(isinstance(formset.non_form_errors(), ErrorList)) 226 for form in formset.forms: 227 self.assertTrue(isinstance(form.errors, ErrorDict)) 228 self.assertTrue(isinstance(form.non_field_errors(), ErrorList)) 203 229 204 230 class CustomWidget(forms.CharField): 205 231 pass