Author: phd
Date: 2007-04-10 08:08:24 -0600 (Tue, 10 Apr 2007)
New Revision: 2506
Modified:
SQLObject/trunk/sqlobject/col.py
SQLObject/trunk/sqlobject/tests/test_datetime.py
Log:
Fixed a bug in DateValidator caused by datetime being a subclass of date.
Modified: SQLObject/trunk/sqlobject/col.py
===================================================================
--- SQLObject/trunk/sqlobject/col.py 2007-04-10 14:07:42 UTC (rev 2505)
+++ SQLObject/trunk/sqlobject/col.py 2007-04-10 14:08:24 UTC (rev 2506)
@@ -1052,7 +1052,7 @@
try:
stime = time.strptime(value, self.format)
except:
- raise validators.Invalid("expected an date/time string of the '%s' format in the DateTimeCol '%s', got %s %r instead" % \
+ raise validators.Invalid("expected a date/time string of the '%s' format in the DateTimeCol '%s', got %s %r instead" % \
(self.format, self.name, type(value), value), value, state)
return datetime.datetime(*stime[:6])
@@ -1084,7 +1084,7 @@
try:
stime = time.strptime(value, self.format)
except:
- raise validators.Invalid("expected an date/time string of the '%s' format in the DateTimeCol '%s', got %s %r instead" % \
+ raise validators.Invalid("expected a date/time string of the '%s' format in the DateTimeCol '%s', got %s %r instead" % \
(self.format, self.name, type(value), value), value, state)
return DateTime.mktime(stime)
@@ -1154,6 +1154,8 @@
if datetime_available:
class DateValidator(DateTimeValidator):
def to_python(self, value, state):
+ if isinstance(value, datetime.datetime):
+ value = value.date()
if isinstance(value, datetime.date):
return value
value = super(DateValidator, self).to_python(value, state)
Modified: SQLObject/trunk/sqlobject/tests/test_datetime.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_datetime.py 2007-04-10 14:07:42 UTC (rev 2505)
+++ SQLObject/trunk/sqlobject/tests/test_datetime.py 2007-04-10 14:08:24 UTC (rev 2506)
@@ -18,8 +18,7 @@
def test_dateTime():
setupClass(DateTime1)
_now = datetime.now()
- _today = date.today()
- dt1 = DateTime1(col1=_now, col2=_today, col3=_now.time())
+ dt1 = DateTime1(col1=_now, col2=_now, col3=_now.time())
assert isinstance(dt1.col1, datetime)
assert dt1.col1.year == _now.year
@@ -30,9 +29,10 @@
assert dt1.col1.second == int(_now.second)
assert isinstance(dt1.col2, date)
- assert dt1.col2.year == _today.year
- assert dt1.col2.month == _today.month
- assert dt1.col2.day == _today.day
+ assert not isinstance(dt1.col2, datetime)
+ assert dt1.col2.year == _now.year
+ assert dt1.col2.month == _now.month
+ assert dt1.col2.day == _now.day
assert isinstance(dt1.col3, time)
assert dt1.col3.hour == _now.hour
|