summaryrefslogtreecommitdiff
path: root/django/forms/forms.py
diff options
context:
space:
mode:
authorStephen Burrows <stephen.r.burrows@gmail.com>2014-05-06 18:14:06 -0700
committerClaude Paroz <claude@2xlibre.net>2014-05-10 10:58:51 +0200
commit0c198035e958a3caa0bd1e0fd9f419bf1308399d (patch)
tree5ac1c255c7e95e529949ceb8fe59d2ae05d009e1 /django/forms/forms.py
parent8a090c21f10c503dd5f29885e78bfb0cb5588ba4 (diff)
[1.7.x] Fixed #22502 -- Fixed microseconds/default/form interaction
Made explicit lack of microsecond handling by built-in datetime form fields. Used that explicitness to appropriately nix microsecond values in bound fields. Thanks Claude Paroz for the review. Backport of a5de0df58 from master.
Diffstat (limited to 'django/forms/forms.py')
-rw-r--r--django/forms/forms.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 5362fd5aaf..2cfd4ec241 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -6,6 +6,7 @@ from __future__ import unicode_literals
from collections import OrderedDict
import copy
+import datetime
import warnings
from django.core.exceptions import ValidationError, NON_FIELD_ERRORS
@@ -590,6 +591,11 @@ class BoundField(object):
data = self.form.initial.get(self.name, self.field.initial)
if callable(data):
data = data()
+ # If this is an auto-generated default date, nix the
+ # microseconds for standardized handling. See #22502.
+ if (isinstance(data, (datetime.datetime, datetime.time)) and
+ not getattr(self.field.widget, 'supports_microseconds', True)):
+ data = data.replace(microsecond=0)
else:
data = self.field.bound_data(
self.data, self.form.initial.get(self.name, self.field.initial)