[Zope-dev] Adding Items to Object Manager and Folders
Ross Boylan
RossBoylan@stanfordalumni.org
Tue, 16 Jul 2002 13:40:08 -0700
The Zope Developer's Guide and the API docs (Zope 2.5) present
different stories about how to add things to object managers. I don't
really follow what the API stuff is doing. This is a request for
clarification.
Devguide says do
def addFunction(dispatcher, id):
"Create object and add to self"
p = SomeProduct(id)
dispatcher.Destination()._setObject(id, p)
This makes sense, though, as commented at
http://www.zope.org//Members/michel/Projects/Interfaces/ObjectManager,
it relies on a private, undocumented method. addFunction is in outer
scope of a module, and is hooked up wtih various calls in ___init__.py.
On the other hand, the ObjectManager API says to do
self.manage_addProduct['OFSP'].manage_addFolder(id, title).
First, what scope should that be done in? Second, this seems to
create one product (OFSP) and then add a folder to it, so that it
creates two, nested products.
The API for Folder mentions manage_addFolder as a constructor, but
again the scope is unclear to me. Presumably it needs to know what to
add it to, but that is not passed in.
Finally, the use of id in two places in the first code snippet (one
apparently associated with the container, the other with the object)
seems like an invitation to trouble. Why is it done that way?
One reason I want to know this is that I'm considering having a
container that would automatically label (or set id) of its contents
(e.g., 'a' is first, 'b' is second....).
Thanks for any light you can shed.