[Zope] 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 ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] set date property from External Method
Gijs Reulen writes: > I would like to set a property with type 'date' from an External Method. > Because the properties all seem to be saved as a string, Zope does not store the properties as strings but as objects of the correct type. If you use the "PropertyManager" interface (as you should), then string values are *converted* to the correct type automatically. Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] set date property from External Method
Hi I would like to set a property with type 'date' from an External Method. Because the properties all seem to be saved as a string, in Python I do: self.prop_datetime = time.strftime('%Y/%m/%d %H:%M:%S.000 GMT+1',time.localtime(time.time())) This results in a optically (!) correct value like: 2000/09/16 17:49:02.000 GMT+1 However, when I call a document which uses the date, as with: Zope produces an error: Zope has encountered an error while publishing this resource. Error Type: NameError Error Value: dd The funny thing is, when I manage the properties and just do a 'save changes', the error is gone and the date is displayed correctly ... It seems to me that the date property is not saved as a string after all ? But what then ? I tried self.prop_datetime = time.localtime(time.time()) and self.prop_datetime = time.time(); both result in a string representing their value but none of them results in a date/time value Gijs Reulen ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )