[Zope3-checkins] SVN: Zope3/trunk/src/zope/schema/ 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 02:49:32 EST 2006


Log message for revision 71128:
  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/trunk/src/zope/schema/_field.py
  U   Zope3/trunk/src/zope/schema/tests/test_date.py

-=-
Modified: Zope3/trunk/src/zope/schema/_field.py
===================================================================
--- Zope3/trunk/src/zope/schema/_field.py	2006-11-15 07:48:38 UTC (rev 71127)
+++ Zope3/trunk/src/zope/schema/_field.py	2006-11-15 07:49:31 UTC (rev 71128)
@@ -205,6 +205,11 @@
     __doc__ = IDate.__doc__
     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__

Modified: Zope3/trunk/src/zope/schema/tests/test_date.py
===================================================================
--- Zope3/trunk/src/zope/schema/tests/test_date.py	2006-11-15 07:48:38 UTC (rev 71127)
+++ Zope3/trunk/src/zope/schema/tests/test_date.py	2006-11-15 07:49:31 UTC (rev 71128)
@@ -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