[Zope-CMF] [RFC] Type mess and allowed_content_types
Luca Olivetti
luca@wetron.es
Sat, 06 Jul 2002 01:54:57 +0200
Luca Olivetti wrote:
> When exactly manage_afterAdd gets called?
> i.e.:
>
> def constructInstance( self, container, id, *args, **kw ):
> """
> Build a "bare" instance of the appropriate type in
> 'container', using 'id' as its id. Return the URL
> of its "immediate" view (typically the metadata form).
> """
> # Get the factory method, performing a security check
> # in the process.
> m = self._getFactoryMethod(container, raise_exc=1)
>
> if m is None:
> raise Unauthorized, ('Cannot create %s' % self.getId())
>
> id = str(id)
>
> if getattr( m, 'isDocTemp', 0 ):
> args = ( m.aq_parent, self.REQUEST ) + args
> kw[ 'id' ] = id
> else:
> args = ( id, ) + args
>
> id = apply( m, args, kw ) or id # allow factory to munge ID
> 1 -->here
> ob = container._getOb( id )
> 2 -->here
> if hasattr(ob, '_setPortalTypeName'):
> ob._setPortalTypeName(self.getId())
>
> wf = getToolByName(ob, 'portal_workflow', None)
> if wf is not None:
> wf.notifyCreated(ob)
>
> return ob
>
> 3 --> or after here?
Ok, looking at the source I see that manage_afterAdd gets called by
_setObject, which is called by the factory constructor, so the correct
answer is 1.
And at this time the PortalTypeName isn't (correcly) set yet.
Maybe constructInstance should pass to the factory method self.getId()
so the factory method can use it to call _setPortalTypeName *before*
calling _setObject?
i.e.: instead of this in the factory method
def addMyType(self,id):
"""Create an instance """
mytype = MyType(id)
self._setObject(id, mytype)
we could assume to have this
def addMyType(self,id,portaltypename):
"""Create an instance """
mytype = MyType(id)
mytype._setPortalTypeName(portaltypename)
self._setObject(id, mytype)
Or maybe don't expect the factory method to call _setObject and call it
in constructInstance at the right time ?
--
Luca Olivetti