Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit b45099eefb9a46264bcb8811dff6013cd1d0f6d6 1 parent ba0734a
@jphalip jphalip authored
View
4 django/forms/widgets.py
@@ -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=()):
View
13 tests/regressiontests/forms/tests/widgets.py
@@ -984,6 +984,10 @@ def test_splithiddendatetime(self):
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 @@ def test_splithiddendatetime(self):
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):
"""

0 comments on commit b45099e

Please sign in to comment.
Something went wrong with that request. Please try again.