[Zope] How to correctly use the PARENTS object?

Peter Sabaini sabaini@niil.at
Mon, 23 Apr 2001 14:00:53 +0200 (CEST)


On Mon, 23 Apr 2001, Gerrie Roos wrote:

> Peter Sabaini wrote:
>
> > I'm not sure myself how to use the PARENTS object myself, but I think
> > you rather want to use the dtml-with tag. dtml-with tells Zope to
> > "look somewhere else" for a name.
> >
> > Eg. something like this should work:
> >
> > <dtml-with Bugsmail>
> >   <dtml-getRecipients>
> >    ...
> >   </dtml-in>
> > </dtml-with>
> >
> > Hth,
> > peter.
> >
> > On Mon, 23 Apr 2001, Gerrie Roos wrote:
> >
> > > I've struggled with this long enough to justify asking help...I've been
> > > through the manuals, FAQ's etc, but somehow my understanding of PARENTS
> > > object is incomplete...
> > >
> > > I have the following directory structure:
> > >
> > > Bugs
> > >         Interface
> > >                 Insert
> > >                         sendMail - a DTML Document
> > >                 BugsMail
> > >                         getRecipients - a Z SQL Method
> > >
> > > I'd like to call and iterate over the results of getRecipients from
> > > sendMail.  So I tried the following in sendMail:
> > >
> > > <dtml-in PARENTS[1].BugsMail.getRecipients>
> > >         <dtml-var someFieldReturnedByGetRecipients>
> > > </dtml-in>
> > >
> > > ...and I get a KeyError for PARENTS[1].BugsMail.getRecipients....
> > >
> > > I tried various other options (albeit somewhat blindly/desparately), eg.
> > > putting the whole PARENTS thing in an expression, etc...What am I
> > > missing?
> > >
> > > What other options are there to traverse a path in a dtml-statement, or
> > > to do what I want to do here?
> > >
> > > Please help, I'm pretty new to this...
>
> Thanks Peter...it works, but I've still got problems...
>
> in getRecipients, I use <dtml-var > to access some other dtml-docs and Z-SQL
> methods that are in
> the BugsMail directory, but they can not be found from within getRecipients!
> If I just directly view getRecipients it works fine, but as soon as
> getRecipients is called from somewhere else using the method you suggested,
> the objects in the BugsMail directory seems to be out of the namespace.
>
> So I actually want to call an object in a totally different branch of the
> Zope tree, and it must be able to access its own default namespace as well...
>
> I even tried another <dtml-with BugsMail> tag in the getRecipients file to
> really bring accross my intention of wanting to call other objects in the
> BugsMail directory, but not only does this seem clumsy, it also doesn't
> work...am I still making sense?

ZSQL Methods dont acquire arguments as other Zope objects do. Instead,
you should pass your arguments directly using Python keyword
syntac. I.e. <dtml-in expr="getRecipients(arg1=value1, arg2=value2,
...)"> ... </dtml-in>. valueX here can be a constant or another zope
variable.

Take a look at the Rel. Database Chapter in the ZopeBook:
http://www.zope.org/Members/michel/ZB/RelationalDatabases.dtml

Hth peter.

-- 

_________________________________________________
peter sabaini, mailto: sabaini@niil.at
-------------------------------------------------