[Zope] from ZClass attribute method to ZInstance?
Jean Lagarde
jean.lagarde@eer-rc.com
Fri, 13 Jul 2001 09:45:48 -0700
I am seeking enlightenment (but please don't answer with a koan ;-)
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?
Here are the two forms of what I want to do, the python script form, which
works as expected, and the dtml method form, which doesn't work.
------ python script (works):
for val in container.objectValues('Field Interface'):
<print stuff based on val>
return printed
------- dtml method (does not work because objectValues returns []):
<dtml-in "objectValues('Field Interface')">
stuff based on sequence-item
</dtml-in>
-------
Cheers,
Jean