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