summaryrefslogtreecommitdiff
path: root/django/forms/widgets.py
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2018-01-30 18:11:05 -0500
committerGitHub <noreply@github.com>2018-01-30 18:11:05 -0500
commit5538729e4ec1adf1c79d94c2b47b5dcf591ad94b (patch)
tree2e0d4e5b49e99dd2f98e8bf96afd9dd75e605386 /django/forms/widgets.py
parent3a4b11873a968b7b566ed4e298dc41e6eb2fd531 (diff)
Fixed #29089 -- Avoided redundant date parsing in SelectDateWidget.format_value().
Diffstat (limited to 'django/forms/widgets.py')
-rw-r--r--django/forms/widgets.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index 76c12e2dcb..0f861f0046 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -1004,7 +1004,10 @@ class SelectDateWidget(Widget):
if isinstance(value, (datetime.date, datetime.datetime)):
year, month, day = value.year, value.month, value.day
elif isinstance(value, str):
- if settings.USE_L10N:
+ match = self.date_re.match(value)
+ if match:
+ year, month, day = [int(val) for val in match.groups()]
+ elif settings.USE_L10N:
input_format = get_format('DATE_INPUT_FORMATS')[0]
try:
d = datetime.datetime.strptime(value, input_format)
@@ -1012,9 +1015,6 @@ class SelectDateWidget(Widget):
pass
else:
year, month, day = d.year, d.month, d.day
- match = self.date_re.match(value)
- if match:
- year, month, day = [int(val) for val in match.groups()]
return {'year': year, 'month': month, 'day': day}
@staticmethod