Ticket #12073: 12073.diff

File 12073.diff, 3.1 KB (added by Koen Biermans, 13 years ago)

patch with test for 12073

  • django/contrib/admin/widgets.py

    diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
    index 0d1f2a9..88b74a4 100644
    a b class AdminDateWidget(forms.DateInput):  
    5454        return forms.Media(js=[static("admin/js/%s" % path) for path in js])
    5555
    5656    def __init__(self, attrs={}, format=None):
    57         super(AdminDateWidget, self).__init__(attrs={'class': 'vDateField', 'size': '10'}, format=format)
     57        attr={'class': 'vDateField', 'size': '10'}
     58        attr.update(attrs)
     59        super(AdminDateWidget, self).__init__(attrs=attr, format=format)
    5860
    5961class AdminTimeWidget(forms.TimeInput):
    6062
    class AdminTimeWidget(forms.TimeInput):  
    6466        return forms.Media(js=[static("admin/js/%s" % path) for path in js])
    6567
    6668    def __init__(self, attrs={}, format=None):
    67         super(AdminTimeWidget, self).__init__(attrs={'class': 'vTimeField', 'size': '8'}, format=format)
     69        attr={'class': 'vTimeField', 'size': '8'}
     70        attr.update(attrs)
     71        super(AdminTimeWidget, self).__init__(attrs=attr, format=format)
    6872
    6973class AdminSplitDateTime(forms.SplitDateTimeWidget):
    7074    """
  • tests/regressiontests/admin_widgets/tests.py

    diff --git a/tests/regressiontests/admin_widgets/tests.py b/tests/regressiontests/admin_widgets/tests.py
    index 08a1a59..751d074 100644
    a b class FilteredSelectMultipleWidgetTest(DjangoTestCase):  
    205205            '<select multiple="multiple" name="test" class="selectfilterstacked">\n</select><script type="text/javascript">addEvent(window, "load", function(e) {SelectFilter.init("id_test", "test", 1, "%(ADMIN_MEDIA_PREFIX)s"); });</script>\n' % admin_media_prefix()
    206206        )
    207207
     208class AdminDateWidgetTest(DjangoTestCase):
     209    def test_render(self):
     210        w = widgets.AdminDateWidget()
     211        self.assertEqual(
     212            conditional_escape(w.render('test', datetime(2007, 12, 1, 9, 30))),
     213            '<input value="2007-12-01" type="text" class="vDateField" name="test" size="10" />',
     214        )
     215        # pass attrs to widget
     216        w = widgets.AdminDateWidget(attrs={'size': 20, 'class': 'myDateField'})
     217        self.assertEqual(
     218            conditional_escape(w.render('test', datetime(2007, 12, 1, 9, 30))),
     219            '<input value="2007-12-01" type="text" class="myDateField" name="test" size="20" />',
     220        )
     221
     222class AdminTimeWidgetTest(DjangoTestCase):
     223    def test_render(self):
     224        w = widgets.AdminTimeWidget()
     225        self.assertEqual(
     226            conditional_escape(w.render('test', datetime(2007, 12, 1, 9, 30))),
     227            '<input value="09:30:00" type="text" class="vTimeField" name="test" size="8" />',
     228        )
     229        # pass attrs to widget
     230        w = widgets.AdminTimeWidget(attrs={'size': 20, 'class': 'myTimeField'})
     231        self.assertEqual(
     232            conditional_escape(w.render('test', datetime(2007, 12, 1, 9, 30))),
     233            '<input value="09:30:00" type="text" class="myTimeField" name="test" size="20" />',
     234        )
    208235
    209236class AdminSplitDateTimeWidgetTest(DjangoTestCase):
    210237    def test_render(self):
Back to Top