[SQL-CVS] r2505 - in SQLObject/branches/0.8: docs sqlobject sqlobject/tests
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2007-04-10 14:07:46
|
Author: phd Date: 2007-04-10 08:07:42 -0600 (Tue, 10 Apr 2007) New Revision: 2505 Modified: SQLObject/branches/0.8/docs/News.txt SQLObject/branches/0.8/sqlobject/col.py SQLObject/branches/0.8/sqlobject/tests/test_datetime.py Log: Fixed a bug in DateValidator caused by datetime being a subclass of date. Modified: SQLObject/branches/0.8/docs/News.txt =================================================================== --- SQLObject/branches/0.8/docs/News.txt 2007-04-10 14:07:07 UTC (rev 2504) +++ SQLObject/branches/0.8/docs/News.txt 2007-04-10 14:07:42 UTC (rev 2505) @@ -151,6 +151,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.8/sqlobject/col.py =================================================================== --- SQLObject/branches/0.8/sqlobject/col.py 2007-04-10 14:07:07 UTC (rev 2504) +++ SQLObject/branches/0.8/sqlobject/col.py 2007-04-10 14:07:42 UTC (rev 2505) @@ -964,7 +964,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]) @@ -996,7 +996,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) @@ -1067,6 +1067,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.8/sqlobject/tests/test_datetime.py =================================================================== --- SQLObject/branches/0.8/sqlobject/tests/test_datetime.py 2007-04-10 14:07:07 UTC (rev 2504) +++ SQLObject/branches/0.8/sqlobject/tests/test_datetime.py 2007-04-10 14:07:42 UTC (rev 2505) @@ -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 |