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:56:39 +0200
commita5de0df58b5431b25a3246a57432db73843be87f (patch)
tree8570266e99b96608e254afdc53f51373551b3a91 /django/forms/forms.py
parent35e1b1efab262ed78b3b8916ec01eb897872fe60 (diff)
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.
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 917987c0be..f248d08726 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
@@ -593,6 +594,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)