From 5538729e4ec1adf1c79d94c2b47b5dcf591ad94b Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 30 Jan 2018 18:11:05 -0500 Subject: [PATCH] Fixed #29089 -- Avoided redundant date parsing in SelectDateWidget.format_value(). --- django/forms/widgets.py | 8 ++++---- 1 file 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