Code

Ticket #16123: patch_for_ticket16123.diff

File patch_for_ticket16123.diff, 1.9 KB (added by wimfeijen, 3 years ago)

Patch for ticket 16123

Line 
1Index: tests/regressiontests/i18n/tests.py
2===================================================================
3--- tests/regressiontests/i18n/tests.py (revision 16351)
4+++ tests/regressiontests/i18n/tests.py (working copy)
5@@ -492,6 +492,17 @@
6                 self.assertEqual(template2.render(context), output2)
7                 self.assertEqual(template3.render(context), output3)
8 
9+    def test_datetime_utf8_encoding(self):
10+        """
11+        Tests whether utf-8 characters are recognized in DateField inputs, f.e. u'31 мая 2011'
12+        """
13+        from django.forms.fields import DateField, DateTimeField
14+        from locale import setlocale, LC_ALL
15+        setlocale(LC_ALL, 'ru_RU.utf-8') # Make sure you have the Russian language installed...
16+        self.assertEqual(DateField().strptime(u'31 мая 2011', '%d %b %Y'), datetime.date(2011, 5, 31))
17+        self.assertEqual(DateTimeField().strptime(u'31 мая 2011', '%d %b %Y'), datetime.datetime(2011, 5, 31))
18+
19+
20 class MiscTests(TestCase):
21 
22     def test_parse_spec_http_header(self):
23Index: django/forms/fields.py
24===================================================================
25--- django/forms/fields.py      (revision 16351)
26+++ django/forms/fields.py      (working copy)
27@@ -373,7 +373,7 @@
28         return super(DateField, self).to_python(value)
29 
30     def strptime(self, value, format):
31-        return datetime.date(*time.strptime(value, format)[:3])
32+        return datetime.date(*time.strptime(value.encode('utf-8'), format)[:3])
33 
34 class TimeField(BaseTemporalField):
35     widget = TimeInput
36@@ -425,7 +425,7 @@
37         return super(DateTimeField, self).to_python(value)
38 
39     def strptime(self, value, format):
40-        return datetime.datetime.strptime(value, format)
41+        return datetime.datetime.strptime(value.encode('utf-8'), format)
42 
43 class RegexField(CharField):
44     def __init__(self, regex, max_length=None, min_length=None, error_message=None, *args, **kwargs):