[Zope] Adding ZClass Instances Programatically -- the theory?

Matt Jacobus mjacobus@iname.com
Mon, 8 Nov 1999 21:03:50 -0000


Kevin,

Thanks for the reply and the howto.

I guess what I was driving at was that I'm interested to know how a DTML
method figures out its idea of this() when it is not passed -- i.e. when
None is passed as the first argument.  Is this stored in the namespace
stack, _?

Would someone point me in the direction of the code that builds _ on DTML
method invocation so that I can see its structure.

Thanks for bearing with my novice questions,

Matt

> -----Original Message-----
> From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Kevin
> Dangoor
> Sent: Sunday, November 07, 1999 10:50 PM
> To: mjacobus@iname.com; zope@zope.org
> Subject: Re: [Zope] Adding ZClass Instances Programatically -- the
> theory?
>
>
> Hi,
>
> ----- Original Message -----
> From: Matt Jacobus <ado06@dial.pipex.com>
> To: <zope@zope.org>
> Sent: Sunday, November 07, 1999 5:01 PM
> Subject: [Zope] Adding ZClass Instances Programatically -- the theory?
>
>
> >
> > In the How-To written by tazzzzz it is explained that in order to add an
> > instance of a zclass you need to make the following call:
> >
> > <dtml-call "YourZClass_add(_.None, _, NoRedir=1)">
> >
> > As per the DTML doc, generally a folder or DTMLDocument is passed in as
> the
> > first argument and the REQUEST is passed as the second.  Would
> someone be
> > kind enough to describe the theory behind passing in None as the client
> and
> > "_" as the REQUEST mapping.
>
> Michel Pelletier talks about this a bit here:
> http://lists.zope.org/pipermail/zope/1999-September/010933.html
>
> Generally, AFAIK, the idea is that you need to pass *something* along to
> tell the method its context. We don't necessarily need to pass a client.
> Passing in the _ namespace works just fine to give the right context.
>
> > In my code I end up using the following so that the new instance will be
> > created in a subfolder:
> >
> >     <dtml-with subfolder>
> >     <dtml-with "manage_addProduct['YourProduct']">
> >        <dtml-call "YourZClass_add(_.None, _, NoRedir=1)">
> >     </dtml-with>
> >     </dtml-with>
> >
> > But once again I'm not entirely sure *why* it is that pushing the
> > subfolder's namespace on top of the stack and then passing the
> stack into
> > the REQUEST argument for YourZClass_add results in the instance being
> added
> > into subfolder.
> >
> > Intuition would tell me to simply pass in the subfolder and the REQUEST
> > object as opposed to manipulating the stack directly and
> passing None and
> _.
> >
> > What I think I'm really trying to understand is how the
> > createInObjectManager method resulting from:
> > <dtml-with "YourZClass.createInObjectManager(REQUEST['id'], REQUEST)">
> > ends up with self populated with the correct folder.
>
> Ahh.. I see why this is somewhat confusing. This is, in fact, a
> function of
> "createInObjectManager". Basically, createInObjectManager expects to be
> called a couple levels down from the target ObjectManager. Why? Because of
> the manage_addProduct that stands in between. This is how
> createInObjectManager is designed to work...
>
> When I wrote that howto, I figured out a lot of it by looking at the
> management interface. If you just take a look at the HTML source
> of pages in
> the management interface, you can kind of see how manage_addProduct is
> called to add objects. Then createinObjectManager will create the
> new object
> in the ObjectManager that called manage_addProduct.
>
> I hope this is more helpful than confusing :)
>
> Kevin
>
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
>           No cross posts or HTML encoding!
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>