Commit b45099ee authored by Julien Phalip's avatar Julien Phalip
Browse files

Fixed #17190 -- Ensured that the `NullBooleanSelect` widget's options get...

Fixed #17190 -- Ensured that the `NullBooleanSelect` widget's options get lazily localized. Thanks to pennersr for the report and to kenth for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17091 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent ba0734af
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -552,7 +552,9 @@ class NullBooleanSelect(Select):
    A Select Widget intended to be used with NullBooleanField.
    """
    def __init__(self, attrs=None):
        choices = ((u'1', ugettext('Unknown')), (u'2', ugettext('Yes')), (u'3', ugettext('No')))
        choices = ((u'1', ugettext_lazy('Unknown')),
                   (u'2', ugettext_lazy('Yes')),
                   (u'3', ugettext_lazy('No')))
        super(NullBooleanSelect, self).__init__(attrs, choices)

    def render(self, name, value, attrs=None, choices=()):
+13 −0
Original line number Diff line number Diff line
@@ -984,6 +984,10 @@ beatle J R Ringo False""")
        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" />')


class NullBooleanSelectLazyForm(Form):
    """Form to test for lazy evaluation. Refs #17190"""
    bool = BooleanField(widget=NullBooleanSelect())

class FormsI18NWidgetsTestCase(TestCase):
    def setUp(self):
        super(FormsI18NWidgetsTestCase, self).setUp()
@@ -1025,6 +1029,15 @@ class FormsI18NWidgetsTestCase(TestCase):
        w.is_localized = True
        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" />')

    def test_nullbooleanselect(self):
        """
        Ensure that the NullBooleanSelect widget's options are lazily
        localized.
        Refs #17190
        """
        f = NullBooleanSelectLazyForm()
        self.assertEqual(f.fields['bool'].widget.render('id_bool', True), u'<select name="id_bool">\n<option value="1">Unbekannt</option>\n<option value="2" selected="selected">Ja</option>\n<option value="3">Nein</option>\n</select>')


class SelectAndTextWidget(MultiWidget):
    """