more consistent in their return values. All three now return None when the passed in string cannot be converted to the required object (this is assumed elsewhere). git-svn-id: http://code.djangoproject.com/svn/django/trunk@3277 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5404e6e93b
commit
c2556874d4
|
@ -773,15 +773,18 @@ class DatetimeField(TextField):
|
||||||
def html2python(data):
|
def html2python(data):
|
||||||
"Converts the field into a datetime.datetime object"
|
"Converts the field into a datetime.datetime object"
|
||||||
import datetime
|
import datetime
|
||||||
date, time = data.split()
|
try:
|
||||||
y, m, d = date.split('-')
|
date, time = data.split()
|
||||||
timebits = time.split(':')
|
y, m, d = date.split('-')
|
||||||
h, mn = timebits[:2]
|
timebits = time.split(':')
|
||||||
if len(timebits) > 2:
|
h, mn = timebits[:2]
|
||||||
s = int(timebits[2])
|
if len(timebits) > 2:
|
||||||
else:
|
s = int(timebits[2])
|
||||||
s = 0
|
else:
|
||||||
return datetime.datetime(int(y), int(m), int(d), int(h), int(mn), s)
|
s = 0
|
||||||
|
return datetime.datetime(int(y), int(m), int(d), int(h), int(mn), s)
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
html2python = staticmethod(html2python)
|
html2python = staticmethod(html2python)
|
||||||
|
|
||||||
class DateField(TextField):
|
class DateField(TextField):
|
||||||
|
@ -806,7 +809,7 @@ class DateField(TextField):
|
||||||
time_tuple = time.strptime(data, '%Y-%m-%d')
|
time_tuple = time.strptime(data, '%Y-%m-%d')
|
||||||
return datetime.date(*time_tuple[0:3])
|
return datetime.date(*time_tuple[0:3])
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
return data
|
return None
|
||||||
html2python = staticmethod(html2python)
|
html2python = staticmethod(html2python)
|
||||||
|
|
||||||
class TimeField(TextField):
|
class TimeField(TextField):
|
||||||
|
|
Loading…
Reference in New Issue