Re: [Zope] Initialization of properties in a ZClass instance?
-----Original Message----- From: Darran Edmundson <Darran.Edmundson@anu.edu.au> To: zope@zope.org <zope@zope.org> Date: Tuesday, September 14, 1999 4:59 AM Subject: [Zope] Initialization of properties in a ZClass instance?
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 raises the question: does every object instance have a creation datetime even though it doesn't explicitly appear on the Properties tab, and if so, is this value available in a DTML method.
This has been talked about earlier on the list. I believe the answer from the DC guys was that the object creation time is not stored in the ZODB (only the last modification time).
On an unrelated note, how can I make each instance of NewsItem's index_html method autmatically visible in the Contents tab and available for editing?
If index_html is a method of the ZClass, it cannot be overridden at the instance level. My method for doing this is to create a DTML method in the ZClass called "default_index_html". Then, the constructor copies the contents of this to a new DTML method inside the instance (that one is called just "index_html"). For convenience sake, I also made a tab for restoring the defaults... This is stuff in the KM|Net News package http://www.zope.org:18200/Members/tazzzzz/kmnn Kevin
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
participants (2)
-
chas -
Kevin Dangoor