Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Julien Phalip authored November 12, 2011
4  django/forms/widgets.py
@@ -552,7 +552,9 @@ class NullBooleanSelect(Select):
552 552
     A Select Widget intended to be used with NullBooleanField.
553 553
     """
554 554
     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')))
556 558
         super(NullBooleanSelect, self).__init__(attrs, choices)
557 559
 
558 560
     def render(self, name, value, attrs=None, choices=()):
13  tests/regressiontests/forms/tests/widgets.py
@@ -984,6 +984,10 @@ def test_splithiddendatetime(self):
984 984
         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" />')
985 985
 
986 986
 
  987
+class NullBooleanSelectLazyForm(Form):
  988
+    """Form to test for lazy evaluation. Refs #17190"""
  989
+    bool = BooleanField(widget=NullBooleanSelect())
  990
+
987 991
 class FormsI18NWidgetsTestCase(TestCase):
988 992
     def setUp(self):
989 993
         super(FormsI18NWidgetsTestCase, self).setUp()
@@ -1025,6 +1029,15 @@ def test_splithiddendatetime(self):
1025 1029
         w.is_localized = True
1026 1030
         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" />')
1027 1031
 
  1032
+    def test_nullbooleanselect(self):
  1033
+        """
  1034
+        Ensure that the NullBooleanSelect widget's options are lazily
  1035
+        localized.
  1036
+        Refs #17190
  1037
+        """
  1038
+        f = NullBooleanSelectLazyForm()
  1039
+        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>')
  1040
+
1028 1041
 
1029 1042
 class SelectAndTextWidget(MultiWidget):
1030 1043
     """

0 notes on commit b45099e

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