Ticket #16479: 16479-formset-forms-error_class-with-tests.diff
File 16479-formset-forms-error_class-with-tests.diff, 1.8 KB (added by , 13 years ago) |
---|
-
tests/regressiontests/forms/tests/formsets.py
1 1 # -*- coding: utf-8 -*- 2 2 from django.forms import Form, CharField, IntegerField, ValidationError, DateField 3 3 from django.forms.formsets import formset_factory, BaseFormSet 4 from django.forms.util import ErrorList 4 5 from django.utils.unittest import TestCase 5 6 6 7 … … 805 806 self.assertEqual(str(reverse_formset[1]), str(forms[-2])) 806 807 self.assertEqual(len(reverse_formset), len(forms)) 807 808 809 def test_formset_error_class(self): 810 # Regression tests for #16479 -- formsets form use ErrorList instead of supplied error_class 811 class CustomErrorList(ErrorList): 812 pass 813 814 formset = FavoriteDrinksFormSet(error_class=CustomErrorList) 815 self.assertEqual(formset.forms[0].error_class, CustomErrorList) 816 808 817 data = { 809 818 'choices-TOTAL_FORMS': '1', # the number of forms rendered 810 819 'choices-INITIAL_FORMS': '0', # the number of forms with initial data -
django/forms/formsets.py
111 111 """ 112 112 Instantiates and returns the i-th form instance in a formset. 113 113 """ 114 defaults = {'auto_id': self.auto_id, 'prefix': self.add_prefix(i)} 114 defaults = { 115 'auto_id': self.auto_id, 116 'prefix': self.add_prefix(i), 117 'error_class': self.error_class, 118 } 115 119 if self.is_bound: 116 120 defaults['data'] = self.data 117 121 defaults['files'] = self.files