Author: julien
Date: 2011-11-12 15:07:51 -0800 (Sat, 12 Nov 2011)
New Revision: 17091

Modified:
   django/trunk/django/forms/widgets.py
   django/trunk/tests/regressiontests/forms/tests/widgets.py
Log:
Fixed #17190 -- Ensured that the `NullBooleanSelect` widget's options get 
lazily localized. Thanks to pennersr for the report and to kenth for the patch.

Modified: django/trunk/django/forms/widgets.py
===================================================================
--- django/trunk/django/forms/widgets.py        2011-11-12 20:30:03 UTC (rev 
17090)
+++ django/trunk/django/forms/widgets.py        2011-11-12 23:07:51 UTC (rev 
17091)
@@ -552,7 +552,9 @@
     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=()):

Modified: django/trunk/tests/regressiontests/forms/tests/widgets.py
===================================================================
--- django/trunk/tests/regressiontests/forms/tests/widgets.py   2011-11-12 
20:30:03 UTC (rev 17090)
+++ django/trunk/tests/regressiontests/forms/tests/widgets.py   2011-11-12 
23:07:51 UTC (rev 17091)
@@ -984,6 +984,10 @@
         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,7 +1029,16 @@
         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):
     """
     MultiWidget subclass

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to