1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

[1.1.X] Fixed #12858. DateTime related widgets now handle custom formats properly in _has_changed. Backport of r12698 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12699 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Joseph Kocherhans
2010-03-07 04:06:23 +00:00
parent e8c768910a
commit 72a659f8f8
2 changed files with 54 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ tests = r"""
>>> from django.forms import *
>>> from django.forms.widgets import RadioFieldRenderer
>>> from django.utils.safestring import mark_safe
>>> from django.utils.encoding import force_unicode
>>> import datetime
>>> import time
>>> import re
@@ -1134,6 +1135,15 @@ u'<input type="text" name="date" value="17/09/2007 12:51" />'
>>> w._has_changed(d, '17/09/2007 12:51')
False
Make sure a custom format works with _has_changed. The hidden input will use
force_unicode to display the initial value.
>>> data = datetime.datetime(2010, 3, 6, 12, 0, 0)
>>> custom_format = '%d.%m.%Y %H:%M'
>>> w = DateTimeInput(format=custom_format)
>>> w._has_changed(force_unicode(data), data.strftime(custom_format))
False
# DateInput ###################################################################
>>> w = DateInput()
@@ -1159,6 +1169,15 @@ u'<input type="text" name="date" value="17/09/2007" />'
>>> w._has_changed(d, '17/09/2007')
False
Make sure a custom format works with _has_changed. The hidden input will use
force_unicode to display the initial value.
>>> data = datetime.date(2010, 3, 6)
>>> custom_format = '%d.%m.%Y'
>>> w = DateInput(format=custom_format)
>>> w._has_changed(force_unicode(data), data.strftime(custom_format))
False
# TimeInput ###################################################################
>>> w = TimeInput()
@@ -1187,6 +1206,15 @@ u'<input type="text" name="time" value="12:51" />'
>>> w._has_changed(t, '12:51')
False
Make sure a custom format works with _has_changed. The hidden input will use
force_unicode to display the initial value.
>>> data = datetime.time(13, 0)
>>> custom_format = '%I:%M %p'
>>> w = TimeInput(format=custom_format)
>>> w._has_changed(force_unicode(data), data.strftime(custom_format))
False
# SplitHiddenDateTimeWidget ###################################################
>>> from django.forms.widgets import SplitHiddenDateTimeWidget