[Zope] from ZClass attribute method to ZInstance?

ender kthangavelu@earthlink.net
Fri, 13 Jul 2001 03:43:29 -0700


On Friday 13 July 2001 09:45, Jean Lagarde wrote:
>>I am seeking enlightenment (but please don't answer with a koan ;-)

what is in a name but a space, when you find your name you will find your 
space and the meaning of things will become clear.

>>I've asked this question before, got no reply, and worked around the
>> problem by using a python script instead of a dtml method, but I needed to
>> add another method to my ZCLass yesterday, and this started to bug me
>> again, because the code would be simpler in a dtml method than in a python
>> script (one loop, no logic).
>>
>>I defined a ZClass based on ObjectManager. I would like a dtml method
>>attribute of the ZClass to loop over the contained objects (of another
>>ZCLass type), i.e.
>>
>><dtml-in "ObjectValues('Field Interface')">
>>
>>But when I call that method from a dtml document, ObjectValues() is not
>>called on what I want, i.e. the instance of my ZCLass container, and so it
>>returns nothing (it does not cause any error, it just returns an empty
>>list). If this was a straight OO environment, I would expect to be able to
>>ask for something like this.ObjectValues(), but I know this is not the case
>>in Zope; 'this' corresponds to the calling dtml document, and not to the
>>ZClass instance to which my method is an attribute of. In the equivalent
>>script, I can use container.ObjectValues, and I have verified that this
>>works. Is there any way to do this (i.e. access the container) in a dtml
>>method, and if not, why not?

the problem here is a common one. dtml documents act as their own container. 
so your dtml method is operating on the document, which rightly has no 
subobjects. if you dtml document was a dtml method things would work as you 
expected.

to be honest i've found very little reason to ever use a dtml document. 

your python script works because the keyword container is tied to the scripts 
physical container which is your zclass. if you changed container to context 
you would reproduce the same behavior that is evidenced by the dtml method.

hope that helps

kapil