Fixed #1188 -- Changed TimeField.html2python to handle microseconds. Thanks, Cheng
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1872 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
6af37477bd
commit
7d0bf5f2dc
1
AUTHORS
1
AUTHORS
|
@ -95,6 +95,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
Rachel Willmer <http://www.willmer.com/kb/>
|
Rachel Willmer <http://www.willmer.com/kb/>
|
||||||
wojtek
|
wojtek
|
||||||
ye7cakf02@sneakemail.com
|
ye7cakf02@sneakemail.com
|
||||||
|
Cheng Zhang
|
||||||
|
|
||||||
A big THANK YOU goes to:
|
A big THANK YOU goes to:
|
||||||
|
|
||||||
|
|
|
@ -746,7 +746,7 @@ class DateField(TextField):
|
||||||
|
|
||||||
class TimeField(TextField):
|
class TimeField(TextField):
|
||||||
"""A FormField that automatically converts its data to a datetime.time object.
|
"""A FormField that automatically converts its data to a datetime.time object.
|
||||||
The data should be in the format HH:MM:SS."""
|
The data should be in the format HH:MM:SS or HH:MM:SS.mmmmmm."""
|
||||||
def __init__(self, field_name, is_required=False, validator_list=[]):
|
def __init__(self, field_name, is_required=False, validator_list=[]):
|
||||||
validator_list = [self.isValidTime] + validator_list
|
validator_list = [self.isValidTime] + validator_list
|
||||||
TextField.__init__(self, field_name, length=8, maxlength=8,
|
TextField.__init__(self, field_name, length=8, maxlength=8,
|
||||||
|
@ -762,11 +762,15 @@ class TimeField(TextField):
|
||||||
"Converts the field into a datetime.time object"
|
"Converts the field into a datetime.time object"
|
||||||
import time, datetime
|
import time, datetime
|
||||||
try:
|
try:
|
||||||
|
part_list = data.split('.')
|
||||||
try:
|
try:
|
||||||
time_tuple = time.strptime(data, '%H:%M:%S')
|
time_tuple = time.strptime(part_list[0], '%H:%M:%S')
|
||||||
except ValueError: # seconds weren't provided
|
except ValueError: # seconds weren't provided
|
||||||
time_tuple = time.strptime(data, '%H:%M')
|
time_tuple = time.strptime(part_list[0], '%H:%M')
|
||||||
return datetime.time(*time_tuple[3:6])
|
t = datetime.time(*time_tuple[3:6])
|
||||||
|
if (len(part_list) == 2):
|
||||||
|
t = t.replace(microsecond=int(part_list[1]))
|
||||||
|
return t
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
return None
|
return None
|
||||||
html2python = staticmethod(html2python)
|
html2python = staticmethod(html2python)
|
||||||
|
|
Loading…
Reference in New Issue