[Zope] Re: Acquiring object from Products instances

Dieter Maurer dieter@handshake.de
Tue, 7 May 2002 20:26:05 +0200


Tille, Andreas writes:
 > On Thu, 2 May 2002, Dieter Maurer wrote:
 > > The standard idiom is:
 > >
 > >     om.manage_addProduct[<product_name>].<constructor>(id,....)
 > >     obj= getattr(om,id)
 > I tried it this way and it works perfectly if the new object is
 > a folder or a dtml-document, but not for a tinytable object.
 > ...
 > The relevant part is shown here:
 > 
 >     ob=MyFolder()
 >     ob.id=str(id)
 >     ob.title=title
 >     self._setObject(id, ob)
 >     ob=self._getOb(id)
 > ...

 > ### From the example ... but does not work anyway
 > ##    ob = getattr(self, id) #we basically get the instance from the ZODB, now has AqWrapper
 > 
 >     ob.manage_addFolder('someid') #works as expected
 >     ob.manage_addTinyTable(id='link_table',
 >                                title='TinyTableObject for '+ob.id,
 >                                columns=column_names)
 > 
 > The last line does not work because it does not put the TinyTable object
 > into the new folder (where I was able to create the example folder named
 > 'someid' but it will be created in the folder below.
I expect this is because your "ob" does not have a "manage_addTinyTable"
method but instead acquires it from "self". It is then
this "self" that is passed in to "manage_addTinyTable" as first
argument and gets the new tiny table.

Probably, "TinyTable" uses old style initialization (see mailing list
archive for an explanation). This would mean, it installs
its constructors directly as so called
folder methods in "OFS.Folder". Only classes derived from
"OFS.Folder" have these constructors.

You may try the official idiom to instantiate classes:

    ob.manage_addProduct['TinyTable'].manage_addTinyTable(...)

I expect it to work even with old style initialization but I am
not sure.

If it does not work, converting the TinyTable to use new style
initialization would probably the best way (again: the mailing
list archives will tell you what's the difference).


Dieter