1
0
mirror of https://github.com/django/django.git synced 2025-10-30 09:06:13 +00:00

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.
This commit is contained in:
Stephen Burrows
2014-05-06 18:14:06 -07:00
committed by Claude Paroz
parent 35e1b1efab
commit a5de0df58b
4 changed files with 35 additions and 3 deletions

View File

@@ -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)

View File

@@ -419,6 +419,7 @@ class Textarea(Widget):
class DateTimeBaseInput(TextInput):
format_key = ''
supports_microseconds = False
def __init__(self, attrs=None, format=None):
super(DateTimeBaseInput, self).__init__(attrs)
@@ -846,6 +847,7 @@ class SplitDateTimeWidget(MultiWidget):
"""
A Widget that splits datetime input into two <input type="text"> boxes.
"""
supports_microseconds = False
def __init__(self, attrs=None, date_format=None, time_format=None):
widgets = (DateInput(attrs=attrs, format=date_format),