Ticket #16709: patch_for_ticket16123.diff
File patch_for_ticket16123.diff, 1.9 KB (added by , 13 years ago) |
---|
-
tests/regressiontests/i18n/tests.py
492 492 self.assertEqual(template2.render(context), output2) 493 493 self.assertEqual(template3.render(context), output3) 494 494 495 def test_datetime_utf8_encoding(self): 496 """ 497 Tests whether utf-8 characters are recognized in DateField inputs, f.e. u'31 мая 2011' 498 """ 499 from django.forms.fields import DateField, DateTimeField 500 from locale import setlocale, LC_ALL 501 setlocale(LC_ALL, 'ru_RU.utf-8') # Make sure you have the Russian language installed... 502 self.assertEqual(DateField().strptime(u'31 мая 2011', '%d %b %Y'), datetime.date(2011, 5, 31)) 503 self.assertEqual(DateTimeField().strptime(u'31 мая 2011', '%d %b %Y'), datetime.datetime(2011, 5, 31)) 504 505 495 506 class MiscTests(TestCase): 496 507 497 508 def test_parse_spec_http_header(self): -
django/forms/fields.py
373 373 return super(DateField, self).to_python(value) 374 374 375 375 def strptime(self, value, format): 376 return datetime.date(*time.strptime(value , format)[:3])376 return datetime.date(*time.strptime(value.encode('utf-8'), format)[:3]) 377 377 378 378 class TimeField(BaseTemporalField): 379 379 widget = TimeInput … … 425 425 return super(DateTimeField, self).to_python(value) 426 426 427 427 def strptime(self, value, format): 428 return datetime.datetime.strptime(value , format)428 return datetime.datetime.strptime(value.encode('utf-8'), format) 429 429 430 430 class RegexField(CharField): 431 431 def __init__(self, regex, max_length=None, min_length=None, error_message=None, *args, **kwargs):