[1.11.x] Fixed #28355 -- Fixed widget rendering of non-ASCII date/time formats on Python 2.
This commit is contained in:
parent
72026fff39
commit
81febf4def
|
@ -463,7 +463,9 @@ class DateTimeBaseInput(TextInput):
|
|||
self.format = format if format else None
|
||||
|
||||
def format_value(self, value):
|
||||
return formats.localize_input(value, self.format or formats.get_format(self.format_key)[0])
|
||||
if value is not None:
|
||||
# localize_input() returns str on Python 2.
|
||||
return force_text(formats.localize_input(value, self.format or formats.get_format(self.format_key)[0]))
|
||||
|
||||
|
||||
class DateInput(DateTimeBaseInput):
|
||||
|
|
|
@ -9,4 +9,6 @@ Django 1.11.4 fixes several bugs in 1.11.3.
|
|||
Bugfixes
|
||||
========
|
||||
|
||||
* ...
|
||||
* Fixed a regression in 1.11.3 on Python 2 where non-ASCII ``format`` values
|
||||
for date/time widgets results in an empty ``value`` in the widget's HTML
|
||||
(:ticket:`28355`).
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import sys
|
||||
from datetime import time
|
||||
from unittest import skipIf
|
||||
|
||||
from django.forms import TimeInput
|
||||
from django.test import override_settings
|
||||
|
@ -43,6 +48,12 @@ class TimeInputTest(WidgetTest):
|
|||
widget = TimeInput(format='%H:%M', attrs={'type': 'time'})
|
||||
self.check_html(widget, 'time', t, html='<input type="time" name="time" value="12:51" />')
|
||||
|
||||
# Test fails on Windows due to http://bugs.python.org/issue8304#msg222667
|
||||
@skipIf(sys.platform.startswith('win'), 'Fails with UnicodeEncodeError error on Windows.')
|
||||
def test_non_ascii_format(self):
|
||||
widget = TimeInput(format='τ-%H:%M')
|
||||
self.check_html(widget, 'time', time(10, 10), '<input type="text" name="time" value="\u03c4-10:10" />')
|
||||
|
||||
@override_settings(USE_L10N=True)
|
||||
@translation.override('de-at')
|
||||
def test_l10n(self):
|
||||
|
|
Loading…
Reference in New Issue