[Zope] Initialization of properties in a ZClass instance?

chas panda@skinnyhippo.com
Wed, 15 Sep 1999 05:35:21 +0800


>>The problem is that
>>/Products/NewsItemProduct/NewsItemClass/propertysheets/common/NewsItemPrope
>rties
>>will not allow me to add a "date" property of type date and
>>leave it blank.  Ideally, I would like this property to
>>default (ie. automatically initialize) to the current datetime.
>>How does one achieve this?  (My guess is that I give it a
>>dummy value in the class definition and then set it in the
>>constructor method?).
>
>Your guess is exactly what I do.

This question has been troubling me for a while :
"what's the point of these initial property values ?"
(It's never stopped me from just creating the properties
with dummy values but it would be nice to know the reasoning).
My initial thought was that these were to be default values 
but that was soon proved to be wrong, as the following 
example demonstrates :


Consider the following properties in a property sheet 'Basic' :

property    datatype    initialvalue
--------    --------    ------------
firstname   string      ""
startdate   date        1999-08-23
length      int         0

On creating the properties, it seems that they need to be given
an intial value. String variables can be left blank since an
empty string is still a string. But the integer and date properties
need initial values as both Darren and Kevin pointed out, so I've
given them dummy values above.

Now I customise the constructor (objectname_addForm) 
so that the user can add the firstname and startdate 
(and not just the ID, which is the default constructor for
an object). I also customise the respective form handler
(objectname_add) to update these values in the property sheet,
using :

<dtml-call "propertysheets.Basic.manage_editProperties(REQUEST)">

BUT this fails because Zope wants the property 'length' to be given
an integer value. Why couldn't it simply inherit it from the property
definition ? That would have seemed the common sense way to go - 
otherwise I can't see the need for the initial values.

Enlightenment ?

chas