[Zope-dev] A couple of ZPatterns questions

Phillip J. Eby pje@telecommunity.com
Thu, 12 Oct 2000 23:31:36 -0500


At 06:15 PM 10/12/00 +1100, Itai Tavor wrote:
>Hi,
>
>1. I want to set some object attributes every time the object is 
>changed (for example, to store the name of the user making the 
>change). I looked at using a Generic Trigger or a SkinScript but I 
>can't figure how to do it with either one.
>
>With a Trigger, I guess I need to set "Set Sttrs" to all the object 
>attributes except the ones I intend to set (otherwise, would setting 
>an attribute in the Trigger cause the Trigger to be called again?) 
>and then call a method to set the attributes - but how do I set the 
>attributes? Do I have to call changeProperties for the object or can 
>I make the change directly on the DataSkin?

You can only change the attributes directly by calling an External Method,
so changeProperties would be the more direct way.

You are correct that you must list the attributes *other* than the ones you
want to change, otherwise you will cause an infinite recursion.  In some
older versions of ZPatterns, you may get the recursion anyway.  :(


>With SkinScript, I can't figure out the STORE and USING syntax... 
>also, if I use WHEN OBJECT CHANGED to change the object, would I get 
>infinite recursion? Can I evaluate REQUEST['AUTHENTICATED_USER'] in 
>the SkinScript or do I need to call a method for that?

Yes, you can say REQUEST.AUTHENTICATED_USER.  No special methods needed.
To write SkinScript equivalent to a generic trigger, the form is:

WHEN OBJECT events STORE set attrs USING expression SAVING stufftosave

This performs the same as a generic trigger with the same parameters.



>2. I want to store a list of products, and give each one an arbitrary 
>number of photos. I can use a Product ZClass, subclassed from 
>ObjectManager and store Image objects inside it. But what will happen 
>to these objects if I use this ZClass in a Rack? And how would I 
>handle storing the objects in SQL tables - I will need to somehow 
>turn each Image object into a table entry, and the same Generic 
>Attribute Provider will have to work with 2 SQL tables. Is there a 
>nice way of doing this? Or should I store the photos in a separate 
>ZClass and use it in another Rack in the Products Specialist?

I would not suggest trying to go the ObjectManager route.  ZPatterns does
not have a good way at present to map child objects into other databases.
Instead, a more custom approach would be appropriate, where you have say an
"images" attribute that is loaded/saved through SQL.  This has the
downside, however, of being either resource intensive or computationally
intensive.

However, it'd probably be best of all to have a Photos specialist, with a
getPhotosForProduct() method, addPhotoToProduct(), and so on.


>Actually, I can't put an Image object on a DataSkin, right? So 
>however I store it, it's going to have to be a my own custom Image 
>object subclassed from DataSkin...

Not necessarily, it depends on your overall structure.  If you want to use
standard Zope Image objects you may indeed want to subclass from DataSkin.