Refs #30578 -- Made SelectDateWidget.format_value() independent of USE_L10N.
This commit is contained in:
parent
04e4f80c1f
commit
00727d384b
|
@ -8,7 +8,6 @@ import warnings
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.forms.utils import to_current_timezone
|
from django.forms.utils import to_current_timezone
|
||||||
from django.templatetags.static import static
|
from django.templatetags.static import static
|
||||||
from django.utils import datetime_safe, formats
|
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
|
# Convert any zeros in the date to empty strings to match the
|
||||||
# empty option value.
|
# empty option value.
|
||||||
year, month, day = [int(val) or '' for val in match.groups()]
|
year, month, day = [int(val) or '' for val in match.groups()]
|
||||||
elif settings.USE_L10N:
|
else:
|
||||||
input_format = get_format('DATE_INPUT_FORMATS')[0]
|
input_format = get_format('DATE_INPUT_FORMATS')[0]
|
||||||
try:
|
try:
|
||||||
d = datetime.datetime.strptime(value, input_format)
|
d = datetime.datetime.strptime(value, input_format)
|
||||||
|
|
|
@ -487,7 +487,7 @@ class SelectDateWidgetTest(WidgetTest):
|
||||||
@override_settings(USE_L10N=False, DATE_INPUT_FORMATS=['%d.%m.%Y'])
|
@override_settings(USE_L10N=False, DATE_INPUT_FORMATS=['%d.%m.%Y'])
|
||||||
def test_custom_input_format(self):
|
def test_custom_input_format(self):
|
||||||
w = SelectDateWidget(years=('0001', '1899', '2009', '2010'))
|
w = SelectDateWidget(years=('0001', '1899', '2009', '2010'))
|
||||||
for values, expected in (
|
for values, expected_value in (
|
||||||
(('0001', '8', '13'), '13.08.0001'),
|
(('0001', '8', '13'), '13.08.0001'),
|
||||||
(('1899', '7', '11'), '11.07.1899'),
|
(('1899', '7', '11'), '11.07.1899'),
|
||||||
(('2009', '3', '7'), '07.03.2009'),
|
(('2009', '3', '7'), '07.03.2009'),
|
||||||
|
@ -497,7 +497,12 @@ class SelectDateWidgetTest(WidgetTest):
|
||||||
'field_%s' % field: value
|
'field_%s' % field: value
|
||||||
for field, value in zip(('year', 'month', 'day'), values)
|
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):
|
def test_format_value(self):
|
||||||
valid_formats = [
|
valid_formats = [
|
||||||
|
|
Loading…
Reference in New Issue