[Zope-CMF] access container in factory method
Tres Seaver
tseaver@zope.com
27 Jan 2003 17:35:56 -0500
On Mon, 2003-01-27 at 16:21, Mark McEahern wrote:
> I have a portal type and in the factory method I want to access the
> container. How do I do that? It's not just naively self--that's the
> factory dispatcher.
>
> E.g.,
>
> def addFoo(self, id):
> container = ... ? ...
Depends on what you need it for. You can obviously acquire from the
"real" container, or the factory methods would be unable to insert the
new object:
def addFoo( self, id )
""" Add a foo to a container.
"""
foo = Foo()
self._setObject( id, foo )
If it really does matter, the acquisition chain of 'self' looks like
this:
pdb> p self.aq_chain
[<__FactoryDispatcher__ instance at 934cf38>, <ProductDispatcher
instance at 8216c70>, <PortalFolder instance at 92ebe18>...]
so the "real" container would be:
'aq_parent( aq_parent( aq_inner( self ) ) )'
Tres.
--
===============================================================
Tres Seaver tseaver@zope.com
Zope Corporation "Zope Dealers" http://www.zope.com