Modifying a zclass property
Hello, I was going through the zope book's chapter "Extending Zope" and I implemented a method called feed (the animal in a ZooExhibit). This method is not in the book, and I coded it as: from DateTime import DateTime context.propertysheets.ExhibitProperties.manage_changeProperties(last_meal_t ime = DateTime()) return context.index_html() This works, but my first (unsuccessfull) try was: from DateTime import DateTime context.last_meal_time = DateTime() return context.index_html() This gives an error: Error Type: TypeError Error Value: attribute-less object (assign or del) Why is last_meal_time not an attribute of the instance? In another method, isHungry, from the book, I can retrieve its value: if (DateTime().timeTime() - context.last_meal_time.timeTime() > 60 * 60 * 8): What's going on? Also, is there any difference between using container and context for an instance of a ZClass? Thanks, Fernando
I don't know the implementations details of the "context" object but I consider "context" as read-only. What you want (I think) is to modify the REQUEST by context.REQUEST.set(key, value). -aj --On Montag, 23. Juni 2003 13:16 Uhr +0200 Fernando Martins <fmartins@hetnet.nl> wrote:
Hello,
I was going through the zope book's chapter "Extending Zope" and I implemented a method called feed (the animal in a ZooExhibit). This method is not in the book, and I coded it as:
from DateTime import DateTime context.propertysheets.ExhibitProperties.manage_changeProperties(last_mea l_t ime = DateTime()) return context.index_html()
This works, but my first (unsuccessfull) try was:
from DateTime import DateTime context.last_meal_time = DateTime() return context.index_html()
This gives an error:
Error Type: TypeError Error Value: attribute-less object (assign or del)
Why is last_meal_time not an attribute of the instance? In another method, isHungry, from the book, I can retrieve its value:
if (DateTime().timeTime() - context.last_meal_time.timeTime() > 60 * 60 * 8):
What's going on?
Also, is there any difference between using container and context for an instance of a ZClass?
Thanks, Fernando
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Thanks for replying, From: Andreas Jung [mailto:andreas@andreas-jung.com]
I don't know the implementations details of the "context" object but I consider "context" as read-only. What you want (I think) is to modify the REQUEST by
context.REQUEST.set(key, value).
Hmm, I can't see how this relates to my problem. Let me rephrase it: I've a ZClass ZooExhibit with an attribute like this: ZooExhibit.PropertySheet.ExhibitProperties.last_meal_time I can access last_meal_time as in if (DateTime().timeTime() - context.last_meal_time.timeTime() > 60 * 60 * 8) (This is being used to show information of an instance of the ZClass) But I can't change the value of an attribute of the instance with: context.last_meal_time = DateTime() My problem seems to be a lack of good understanding of what is the context object and its relation with the instance of the ZClass. Cheers, Fernando
You cannot assign to attributes of an object from restricted Python. What you probably want is: eprops = context.propertysheets.ExhibitProperties eprops.manage_changeProperties(last_meal_time=DateTime()) Hope this helps, Stefan On Montag, Jun 23, 2003, at 19:19 Europe/Vienna, Fernando Martins wrote:
Hmm, I can't see how this relates to my problem. Let me rephrase it:
I've a ZClass ZooExhibit with an attribute like this: ZooExhibit.PropertySheet.ExhibitProperties.last_meal_time
I can access last_meal_time as in if (DateTime().timeTime() - context.last_meal_time.timeTime() > 60 * 60 * 8) (This is being used to show information of an instance of the ZClass)
But I can't change the value of an attribute of the instance with: context.last_meal_time = DateTime()
My problem seems to be a lack of good understanding of what is the context object and its relation with the instance of the ZClass.
-- The time has come to start talking about whether the emperor is as well dressed as we are supposed to think he is. /Pete McBreen/
participants (3)
-
Andreas Jung -
Fernando Martins -
Stefan H. Holek