API documentation bug (was: [Zope] set date property from External Method)
Gijs Reulen writes:
If you use the "PropertyManager" interface (as you should), then string values are *converted* to the correct type automatically.
Not so, according to my info and tests:
From the Zope 2.2.1 API docs on manage_changeProperties(self, REQUEST=None, **kw):
"... Note that no type checking or conversion happens when this method is called, so it is the caller's responsibility to ensure that the updated values are of the correct type. This should probably change. ..." The API doc is old and outdated:
Both "manage_changeProperties" and "manage_editProperties" call "_updateProperty". "_updateProperty" has this code: def _updateProperty(self, id, value): # Update the value of an existing property. If value # is a string, an attempt will be made to convert # the value to the type of the existing property. self._wrapperCheck(value) if not self.hasProperty(id): raise 'Bad Request', 'The property %s does not exist' % id if type(value)==type(''): proptype=self.getPropertyType(id) or 'string' if type_converters.has_key(proptype): value=type_converters[proptype](value) self._setPropValue(id, value) Thus, if you pass a string to "manage_changeProperty" or "manage_editProperty", it is converted to the correct type. A Date property uses the type "DateTime.DateTime".
I tried things like: self.manage_changeProperties(my_prop=time.strftime('%Y/%m/%d %H:%M:%S.000 GMT+1',time.localtime(time.time()))) I checked (Zope 2.2.1):
self.manage_changeProperties(my_prop='2000/9/12') You can pass any DateTime value, too, e.g.: self.manage_changeProperties(my_prop= DateTime()) Dieter
participants (1)
-
Dieter Maurer