Ticket #16123: patch_for_ticket16123.diff

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

Patch for ticket 16123

  • tests/regressiontests/i18n/tests.py

     
    492492                self.assertEqual(template2.render(context), output2)
    493493                self.assertEqual(template3.render(context), output3)
    494494
     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
    495506class MiscTests(TestCase):
    496507
    497508    def test_parse_spec_http_header(self):
  • django/forms/fields.py

     
    373373        return super(DateField, self).to_python(value)
    374374
    375375    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])
    377377
    378378class TimeField(BaseTemporalField):
    379379    widget = TimeInput
     
    425425        return super(DateTimeField, self).to_python(value)
    426426
    427427    def strptime(self, value, format):
    428         return datetime.datetime.strptime(value, format)
     428        return datetime.datetime.strptime(value.encode('utf-8'), format)
    429429
    430430class RegexField(CharField):
    431431    def __init__(self, regex, max_length=None, min_length=None, error_message=None, *args, **kwargs):
Back to Top