Ticket #16479: 16479-formset-forms-error_class-with-tests_updated.diff

File 16479-formset-forms-error_class-with-tests_updated.diff, 1.7 KB (added by vicould, 3 years ago)

Updated test import

  • django/forms/formsets.py

    diff --git a/django/forms/formsets.py b/django/forms/formsets.py
    index 42d25fa..6296185 100644
    a b class BaseFormSet(object): 
    123123        """
    124124        Instantiates and returns the i-th form instance in a formset.
    125125        """
    126         defaults = {'auto_id': self.auto_id, 'prefix': self.add_prefix(i)}
     126        defaults = {
     127            'auto_id': self.auto_id,
     128                   'prefix': self.add_prefix(i),
     129                   'error_class': self.error_class,
     130               }
    127131        if self.is_bound:
    128132            defaults['data'] = self.data
    129133            defaults['files'] = self.files
  • tests/regressiontests/forms/tests/formsets.py

    diff --git a/tests/regressiontests/forms/tests/formsets.py b/tests/regressiontests/forms/tests/formsets.py
    index 3decd1f..b3ceee5 100644
    a b from __future__ import unicode_literals 
    33
    44from django.forms import Form, CharField, IntegerField, ValidationError, DateField
    55from django.forms.formsets import formset_factory, BaseFormSet
     6from django.forms.util import ErrorList
    67from django.test import TestCase
    78
    89
    class FormsFormsetTestCase(TestCase): 
    847848        self.assertTrue(formset)
    848849
    849850
     851    def test_formset_error_class(self):
     852        # Regression tests for #16479 -- formsets form use ErrorList instead of supplied error_class
     853        class CustomErrorList(ErrorList):
     854            pass
     855
     856        formset = FavoriteDrinksFormSet(error_class=CustomErrorList)
     857        self.assertEqual(formset.forms[0].error_class, CustomErrorList)
     858
     859
    850860data = {
    851861    'choices-TOTAL_FORMS': '1', # the number of forms rendered
    852862    'choices-INITIAL_FORMS': '0', # the number of forms with initial data
Back to Top