[Zope] from ZClass attribute method to ZInstance?

Jean Lagarde jean.lagarde@eer-rc.com
Fri, 13 Jul 2001 15:05:59 -0700


Thanks Kapil,

I more or less already understood what you wrote (except for the first
sentence, but I asked for that one ;-), and my question was specifically to
know if there was a way to achieve the same thing as with 'container' in a
script, but in a dtml method (irrespective of how the method was called).
Although you did not state it specifically, your answer seems to indicate
that it is not possible. Is the non-availability of the Zinstance in a dtml
method a security issue, and implementation issue, or just an oversight?
Seems to me it would be a useful thing to have.

Cheers,

Jean

> -----Original Message-----
> From: ender [mailto:kthangavelu@earthlink.net]
> Sent: Friday, July 13, 2001 03:43
> To: Jean Lagarde; zope@zope.org
> Subject: Re: [Zope] from ZClass attribute method to ZInstance?
>
>
> 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