From f5831b03c908d9d4bf59f0a0cef4e3db221367ca Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sun, 21 Oct 2007 14:50:20 +0000 Subject: [PATCH] DateTimeField can now clean values that come from SplitDateTimeWidget. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6577 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/newforms/fields.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/django/newforms/fields.py b/django/newforms/fields.py index a39987e1b5..26935140c3 100644 --- a/django/newforms/fields.py +++ b/django/newforms/fields.py @@ -300,6 +300,12 @@ class DateTimeField(Field): return value if isinstance(value, datetime.date): return datetime.datetime(value.year, value.month, value.day) + if isinstance(value, list): + # Input comes from a SplitDateTimeWidget, for example. So, it's two + # components: date and time. + if len(value) != 2: + raise ValidationError(ugettext(u'Enter a valid date/time.')) + value = '%s %s' % tuple(value) for format in self.input_formats: try: return datetime.datetime(*time.strptime(value, format)[:6])