summaryrefslogtreecommitdiff
path: root/django/forms
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2011-06-09 17:03:45 +0000
committerAndrew Godwin <andrew@aeracode.org>2011-06-09 17:03:45 +0000
commitdce278673a409a10c1f74f597035b737bbf6a017 (patch)
treeec584749ee483103b5c352f4604875041aaf09fe /django/forms
parentdfcde78161866ad2c2c863c0a8c48480c3228f84 (diff)
Fixed #9459: forms.HiddenInput and DateTime field loses microseconds. Thanks to mt.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16347 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/forms')
-rw-r--r--django/forms/fields.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index a5ea81d4b6..dd23b12e5c 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -338,7 +338,15 @@ class BaseTemporalField(Field):
try:
return self.strptime(value, format)
except ValueError:
- continue
+ if format.endswith('.%f'):
+ if not value.count('.')==1:
+ continue
+ try:
+ datetime_str, usecs_str = value.rsplit('.', 1)
+ usecs = int(usecs_str)
+ return datetime.datetime(*time.strptime(datetime_str, format[:-3])[:6]+(usecs,))
+ except ValueError:
+ continue
raise ValidationError(self.error_messages['invalid'])
def strptime(self, value, format):
@@ -417,7 +425,7 @@ class DateTimeField(BaseTemporalField):
return super(DateTimeField, self).to_python(value)
def strptime(self, value, format):
- return datetime.datetime(*time.strptime(value, format)[:6])
+ return datetime.datetime.strptime(value, format)
class RegexField(CharField):
def __init__(self, regex, max_length=None, min_length=None, error_message=None, *args, **kwargs):