mirror of
https://github.com/django/django.git
synced 2025-10-28 08:06:09 +00:00
Fixed #10288 -- Corrected _has_changed handling of DateTimeInput, DateInput, TimeInput, and SplitDateTimeWidget when a custom date/time format is in use. Thanks to Koen Biermans for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10641 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -294,14 +294,21 @@ class DateInput(Input):
|
||||
if format:
|
||||
self.format = format
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
def _format_value(self, value):
|
||||
if value is None:
|
||||
value = ''
|
||||
return ''
|
||||
elif hasattr(value, 'strftime'):
|
||||
value = datetime_safe.new_date(value)
|
||||
value = value.strftime(self.format)
|
||||
return value.strftime(self.format)
|
||||
return value
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
value = self._format_value(value)
|
||||
return super(DateInput, self).render(name, value, attrs)
|
||||
|
||||
def _has_changed(self, initial, data):
|
||||
return super(DateInput, self)._has_changed(self._format_value(initial), data)
|
||||
|
||||
class DateTimeInput(Input):
|
||||
input_type = 'text'
|
||||
format = '%Y-%m-%d %H:%M:%S' # '2006-10-25 14:30:59'
|
||||
@@ -311,14 +318,21 @@ class DateTimeInput(Input):
|
||||
if format:
|
||||
self.format = format
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
def _format_value(self, value):
|
||||
if value is None:
|
||||
value = ''
|
||||
return ''
|
||||
elif hasattr(value, 'strftime'):
|
||||
value = datetime_safe.new_datetime(value)
|
||||
value = value.strftime(self.format)
|
||||
return value.strftime(self.format)
|
||||
return value
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
value = self._format_value(value)
|
||||
return super(DateTimeInput, self).render(name, value, attrs)
|
||||
|
||||
def _has_changed(self, initial, data):
|
||||
return super(DateTimeInput, self)._has_changed(self._format_value(initial), data)
|
||||
|
||||
class TimeInput(Input):
|
||||
input_type = 'text'
|
||||
format = '%H:%M:%S' # '14:30:59'
|
||||
@@ -328,13 +342,20 @@ class TimeInput(Input):
|
||||
if format:
|
||||
self.format = format
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
def _format_value(self, value):
|
||||
if value is None:
|
||||
value = ''
|
||||
return ''
|
||||
elif hasattr(value, 'strftime'):
|
||||
value = value.strftime(self.format)
|
||||
return value.strftime(self.format)
|
||||
return value
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
value = self._format_value(value)
|
||||
return super(TimeInput, self).render(name, value, attrs)
|
||||
|
||||
def _has_changed(self, initial, data):
|
||||
return super(TimeInput, self)._has_changed(self._format_value(initial), data)
|
||||
|
||||
class CheckboxInput(Widget):
|
||||
def __init__(self, attrs=None, check_test=bool):
|
||||
super(CheckboxInput, self).__init__(attrs)
|
||||
@@ -422,11 +443,11 @@ class NullBooleanSelect(Select):
|
||||
|
||||
def value_from_datadict(self, data, files, name):
|
||||
value = data.get(name, None)
|
||||
return {u'2': True,
|
||||
True: True,
|
||||
'True': True,
|
||||
u'3': False,
|
||||
'False': False,
|
||||
return {u'2': True,
|
||||
True: True,
|
||||
'True': True,
|
||||
u'3': False,
|
||||
'False': False,
|
||||
False: False}.get(value, None)
|
||||
|
||||
def _has_changed(self, initial, data):
|
||||
|
||||
Reference in New Issue
Block a user