Ticket #17190: 17190.diff

File 17190.diff, 2.1 KB (added by kenth, 13 years ago)

patch with tests

  • django/forms/widgets.py

    diff --git a/django/forms/widgets.py b/django/forms/widgets.py
    index 5b50f37..8c1e20b 100644
    a b class NullBooleanSelect(Select):  
    552552    A Select Widget intended to be used with NullBooleanField.
    553553    """
    554554    def __init__(self, attrs=None):
    555         choices = ((u'1', ugettext('Unknown')), (u'2', ugettext('Yes')), (u'3', ugettext('No')))
     555        choices = ((u'1', ugettext_lazy('Unknown')),
     556                   (u'2', ugettext_lazy('Yes')),
     557                   (u'3', ugettext_lazy('No')))
    556558        super(NullBooleanSelect, self).__init__(attrs, choices)
    557559
    558560    def render(self, name, value, attrs=None, choices=()):
  • tests/regressiontests/forms/tests/widgets.py

    diff --git a/tests/regressiontests/forms/tests/widgets.py b/tests/regressiontests/forms/tests/widgets.py
    index 2424bea..a1d98e9 100644
    a b beatle J R Ringo False""")  
    984984        self.assertEqual(w.render('date', datetime.datetime(2007, 9, 17, 12, 51)), u'<input type="hidden" name="date_0" value="2007-09-17" /><input type="hidden" name="date_1" value="12:51:00" />')
    985985
    986986
     987class NullSelectNotLazyForm(Form):
     988    """Form to test for lazy evaluation #17190"""
     989    name = CharField(widget=NullBooleanSelect())
     990
     991
    987992class FormsI18NWidgetsTestCase(TestCase):
    988993    def setUp(self):
    989994        super(FormsI18NWidgetsTestCase, self).setUp()
    class FormsI18NWidgetsTestCase(TestCase):  
    10251030        w.is_localized = True
    10261031        self.assertEqual(w.render('date', datetime.datetime(2007, 9, 17, 12, 51)), u'<input type="hidden" name="date_0" value="17.09.2007" /><input type="hidden" name="date_1" value="12:51:00" />')
    10271032
     1033    def test_nullbooleanselect(self):
     1034        """test for lazy evaluation #17190"""
     1035        f = NullSelectNotLazyForm()
     1036        self.assertEqual(f.as_table(), u'<tr><th><label for="id_name">Name:</label></th><td><select name="name" id="id_name">\n<option value="1" selected="selected">Unbekannt</option>\n<option value="2">Ja</option>\n<option value="3">Nein</option>\n</select></td></tr>')
     1037
    10281038
    10291039class SelectAndTextWidget(MultiWidget):
    10301040    """
Back to Top