Refs #30578 -- Made SelectDateWidget.format_value() independent of USE_L10N.

This commit is contained in:
Claude Paroz 2020-07-10 12:57:39 +02:00 committed by Mariusz Felisiak
parent 04e4f80c1f
commit 00727d384b
2 changed files with 8 additions and 4 deletions

View File

@ -8,7 +8,6 @@ import warnings
from collections import defaultdict
from itertools import chain
from django.conf import settings
from django.forms.utils import to_current_timezone
from django.templatetags.static import static
from django.utils import datetime_safe, formats
@ -1028,7 +1027,7 @@ class SelectDateWidget(Widget):
# Convert any zeros in the date to empty strings to match the
# empty option value.
year, month, day = [int(val) or '' for val in match.groups()]
elif settings.USE_L10N:
else:
input_format = get_format('DATE_INPUT_FORMATS')[0]
try:
d = datetime.datetime.strptime(value, input_format)

View File

@ -487,7 +487,7 @@ class SelectDateWidgetTest(WidgetTest):
@override_settings(USE_L10N=False, DATE_INPUT_FORMATS=['%d.%m.%Y'])
def test_custom_input_format(self):
w = SelectDateWidget(years=('0001', '1899', '2009', '2010'))
for values, expected in (
for values, expected_value in (
(('0001', '8', '13'), '13.08.0001'),
(('1899', '7', '11'), '11.07.1899'),
(('2009', '3', '7'), '07.03.2009'),
@ -497,7 +497,12 @@ class SelectDateWidgetTest(WidgetTest):
'field_%s' % field: value
for field, value in zip(('year', 'month', 'day'), values)
}
self.assertEqual(w.value_from_datadict(data, {}, 'field'), expected)
self.assertEqual(w.value_from_datadict(data, {}, 'field'), expected_value)
expected_dict = {
field: int(value)
for field, value in zip(('year', 'month', 'day'), values)
}
self.assertEqual(w.format_value(expected_value), expected_dict)
def test_format_value(self):
valid_formats = [