diff options
| author | Jannis Leidel <jannis@leidel.info> | 2009-12-30 22:11:48 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2009-12-30 22:11:48 +0000 |
| commit | bf33d3eb1d20157a09b4bf1f36f9c928bc1cabc7 (patch) | |
| tree | 463fa22603dbfc4d3677748cd06512349eb8f626 /django/forms | |
| parent | 6eb02fa9bbd6e68d57f6b5b6e7419271ca4fd0ab (diff) | |
Fixed #12444 - Date based widgets now correctly handle input values when using locale-aware formatting. Also fixes #7656.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12029 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/widgets.py | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py index aabd1b017d..c16c239de1 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -10,8 +10,7 @@ from django.utils.html import escape, conditional_escape from django.utils.translation import ugettext from django.utils.encoding import StrAndUnicode, force_unicode from django.utils.safestring import mark_safe -from django.utils.formats import localize -from django.utils import datetime_safe +from django.utils import datetime_safe, formats from datetime import time from util import flatatt from urlparse import urljoin @@ -209,7 +208,7 @@ class Input(Widget): final_attrs = self.build_attrs(attrs, type=self.input_type, name=name) if value != '': # Only add the 'value' attribute if a value is non-empty. - final_attrs['value'] = force_unicode(localize(value, is_input=True)) + final_attrs['value'] = force_unicode(formats.localize_input(value)) return mark_safe(u'<input%s />' % flatatt(final_attrs)) class TextInput(Input): @@ -284,7 +283,7 @@ class Textarea(Widget): class DateInput(Input): input_type = 'text' - format = '%Y-%m-%d' # '2006-10-25' + format = None def __init__(self, attrs=None, format=None): super(DateInput, self).__init__(attrs) @@ -295,8 +294,7 @@ class DateInput(Input): if value is None: return '' elif hasattr(value, 'strftime'): - value = datetime_safe.new_date(value) - return value.strftime(self.format) + return formats.localize_input(value, self.format) return value def render(self, name, value, attrs=None): @@ -308,7 +306,7 @@ class DateInput(Input): class DateTimeInput(Input): input_type = 'text' - format = '%Y-%m-%d %H:%M:%S' # '2006-10-25 14:30:59' + format = None def __init__(self, attrs=None, format=None): super(DateTimeInput, self).__init__(attrs) @@ -319,8 +317,7 @@ class DateTimeInput(Input): if value is None: return '' elif hasattr(value, 'strftime'): - value = datetime_safe.new_datetime(value) - return value.strftime(self.format) + return formats.localize_input(value, self.format) return value def render(self, name, value, attrs=None): @@ -332,7 +329,7 @@ class DateTimeInput(Input): class TimeInput(Input): input_type = 'text' - format = '%H:%M:%S' # '14:30:59' + format = None def __init__(self, attrs=None, format=None): super(TimeInput, self).__init__(attrs) @@ -343,7 +340,7 @@ class TimeInput(Input): if value is None: return '' elif hasattr(value, 'strftime'): - return value.strftime(self.format) + return formats.localize_input(value, self.format) return value def render(self, name, value, attrs=None): |
