Ticket #15912: 15912.super.diff

File 15912.super.diff, 1.8 KB (added by Preston Timmons, 13 years ago)

Same patch using super method

  • django/forms/fields.py

    diff --git a/django/forms/fields.py b/django/forms/fields.py
    index 113a5aa..f538ad6 100644
    a b class CharField(Field):  
    194194        return smart_unicode(value)
    195195
    196196    def widget_attrs(self, widget):
     197        attrs = super(CharField, self).widget_attrs(widget)
    197198        if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)):
    198199            # The HTML attribute is maxlength, not max_length.
    199             return {'maxlength': str(self.max_length)}
     200            attrs.update({'maxlength': str(self.max_length)})
     201        return attrs
    200202
    201203class IntegerField(Field):
    202204    default_error_messages = {
  • tests/regressiontests/forms/tests/fields.py

    diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
    index 6780413..9c138a8 100644
    a b class FieldsTests(TestCase):  
    131131        self.assertEqual(f.max_length, None)
    132132        self.assertEqual(f.min_length, 10)
    133133
     134    def test_charfield_widget_attrs(self):
     135        """ Regression test for #15912 """
     136
     137        # Return an empty dictionary if max_length is None
     138        f = CharField()
     139        self.assertEqual(f.widget_attrs(TextInput()), {})
     140
     141        # Or if the widget is not TextInput or PasswordInput
     142        f = CharField(max_length=10)
     143        self.assertEqual(f.widget_attrs(HiddenInput()), {})
     144
     145        # Otherwise, return a maxlength attribute equal to max_length
     146        self.assertEqual(f.widget_attrs(TextInput()), {'maxlength': '10'})
     147        self.assertEqual(f.widget_attrs(PasswordInput()), {'maxlength': '10'})
     148
    134149    # IntegerField ################################################################
    135150
    136151    def test_integerfield_1(self):
Back to Top