[Zope-dev] Re: [Zope-CMF] How to get Type in manage_afterAdd?

Florent Guillaume fg@nuxeo.com
Thu, 31 Jan 2002 18:57:55 +0000 (UTC)


Hmmm, probably I should have used the term "factory" instead of
"constructor" in that last mail...

Florent

Florent Guillaume  <fg@nuxeo.com> wrote:
> [sent to zope-dev]
> 
> This problem is due to a deep bug in the current implementation of the
> Types Tool: a created object has no way to know its portal_type during
> construction (the constructor doesn't have this information, thus nor
> __init__ nor the hooks like manage_afterAdd can have it).
> 
> I thought that this bug was already in the Tracker but I don't find it.
> Anyone knows ?
> 
> Anyway I'd propose the following: we need, in constructInstance, to
> somehow pass the portal_type to the object constructor. Unfortunately
> this has to be backwards-compatible with all the constructors out there
> that don't know about it. I see two possible ugly solutions to do it:
> 
>   - do "constructor.__portal_type = portal_type" before calling
>     constructor(...), and the constructor does something like:
>     def manage_addFoo(...):
>       try:
>         portal_type = manage_addFoo.__portal_type
>         manage_addFoo.__portal_type = None
>       except:
>         portal_type = None
>       ...
> 
>   - in constructInstance, use introspection (getargspec) to look
>     if the constructor accepts a portal_type=xxx named parameter,
>     and pass it if it does.
> 
> Anyone sees something cleaner ? :-)

-- 
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 10  http://nuxeo.com  mailto:fg@nuxeo.com