Author: phd
Date: 2007-04-10 08:07:07 -0600 (Tue, 10 Apr 2007)
New Revision: 2504
Modified:
SQLObject/branches/0.7/docs/News.txt
SQLObject/branches/0.7/sqlobject/col.py
SQLObject/branches/0.7/sqlobject/tests/test_datetime.py
Log:
Fixed a bug in DateValidator caused by datetime being a subclass of date.
Modified: SQLObject/branches/0.7/docs/News.txt
===================================================================
--- SQLObject/branches/0.7/docs/News.txt 2007-04-10 06:13:57 UTC (rev 2503)
+++ SQLObject/branches/0.7/docs/News.txt 2007-04-10 14:07:07 UTC (rev 2504)
@@ -16,6 +16,8 @@
* Fixed test_deep_inheritance.py - setup classes in the correct order
(required for Postgres 8.0+ which is strict about referential integrity).
+* Fixed a bug in DateValidator caused by datetime being a subclass of date.
+
SQLObject 0.7.4
===============
Modified: SQLObject/branches/0.7/sqlobject/col.py
===================================================================
--- SQLObject/branches/0.7/sqlobject/col.py 2007-04-10 06:13:57 UTC (rev 2503)
+++ SQLObject/branches/0.7/sqlobject/col.py 2007-04-10 14:07:07 UTC (rev 2504)
@@ -951,7 +951,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])
@@ -983,7 +983,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)
@@ -1054,6 +1054,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/branches/0.7/sqlobject/tests/test_datetime.py
===================================================================
--- SQLObject/branches/0.7/sqlobject/tests/test_datetime.py 2007-04-10 06:13:57 UTC (rev 2503)
+++ SQLObject/branches/0.7/sqlobject/tests/test_datetime.py 2007-04-10 14:07:07 UTC (rev 2504)
@@ -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
|