[Zope3-checkins] SVN: Zope3/branches/3.3/ backport from trunk: fix validate method of schema.Date, now it does not accept datetime objects anymore. this is needed because datetime and date values are not comparable

Bernd Dorn bernd.dorn at fhv.at
Wed Nov 15 03:00:29 EST 2006


Log message for revision 71131:
  backport from trunk: fix validate method of schema.Date, now it does not accept datetime objects anymore. this is needed because datetime and date values are not comparable

Changed:
  U   Zope3/branches/3.3/doc/CHANGES.txt
  U   Zope3/branches/3.3/src/zope/schema/_field.py
  U   Zope3/branches/3.3/src/zope/schema/tests/test_date.py

-=-
Modified: Zope3/branches/3.3/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.3/doc/CHANGES.txt	2006-11-15 07:57:31 UTC (rev 71130)
+++ Zope3/branches/3.3/doc/CHANGES.txt	2006-11-15 08:00:29 UTC (rev 71131)
@@ -1,4 +1,4 @@
-Zope Changes
+HZope Changes
 
   This file contains change information for the current Zope release.
   Change information for previous versions of Zope can be found in the
@@ -10,6 +10,10 @@
 
     Bugfixes
 
+      - Fixed validate method of schema.Date, now it does not accept
+        datetime objects anymore. this is needed because datetime and
+        date values are not comparable
+
       - Fixed issue 730: Subversion 1.4 breaks mkzopeinstance.py
 
       - Fixed zope.annotation.factory to correctly setup containment for

Modified: Zope3/branches/3.3/src/zope/schema/_field.py
===================================================================
--- Zope3/branches/3.3/src/zope/schema/_field.py	2006-11-15 07:57:31 UTC (rev 71130)
+++ Zope3/branches/3.3/src/zope/schema/_field.py	2006-11-15 08:00:29 UTC (rev 71131)
@@ -179,6 +179,11 @@
     implements(IDate)
     _type = date
 
+    def _validate(self, value):
+        super(Date, self)._validate(value)
+        if isinstance(value, datetime):
+            raise WrongType(value, self._type)
+
 class Timedelta(Orderable, Field):
     __doc__ = ITimedelta.__doc__
     implements(ITimedelta)

Modified: Zope3/branches/3.3/src/zope/schema/tests/test_date.py
===================================================================
--- Zope3/branches/3.3/src/zope/schema/tests/test_date.py	2006-11-15 07:57:31 UTC (rev 71130)
+++ Zope3/branches/3.3/src/zope/schema/tests/test_date.py	2006-11-15 08:00:29 UTC (rev 71131)
@@ -17,7 +17,7 @@
 """
 from unittest import main, makeSuite
 from zope.schema import Date
-from zope.schema.interfaces import RequiredMissing, InvalidValue
+from zope.schema.interfaces import RequiredMissing, InvalidValue, WrongType
 from zope.schema.interfaces import TooSmall, TooBig
 from zope.schema.tests.test_field import FieldTestBase
 from datetime import datetime, date
@@ -37,6 +37,7 @@
                                     readonly=False, required=False)
         field.validate(None)
         field.validate(datetime.now().date())
+        self.assertRaises(WrongType, field.validate, datetime.now())
 
     def testValidateRequired(self):
         field = self._Field_Factory(title=u'Date field', description=u'',



More information about the Zope3-Checkins mailing list