Author: mtredinnick
Date: 2007-10-21 09:50:20 -0500 (Sun, 21 Oct 2007)
New Revision: 6577

Modified:
   django/trunk/django/newforms/fields.py
Log:
DateTimeField can now clean values that come from SplitDateTimeWidget.


Modified: django/trunk/django/newforms/fields.py
===================================================================
--- django/trunk/django/newforms/fields.py      2007-10-21 12:24:37 UTC (rev 
6576)
+++ django/trunk/django/newforms/fields.py      2007-10-21 14:50:20 UTC (rev 
6577)
@@ -300,6 +300,12 @@
             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])


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to