[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 Jon Edwards <[EMAIL PROTECTED]> wrote: > I've created a new product - "organisation", which has a property > "org_type", which I set in manage_afterAdd by doing - > > self.org_type = self.portal_type > > - which then gets catalogued. Works fine for the basic product, but if I use > the Portal Types tool to make a new type "Hospital", using "organisation" as > the underlying default type, it should use "Hospital" as the "org_type". > > I've tried everything I can think of in place of self.portal_type > (meta_type, Type(), _getPortalTypeName(), etc.) but I still get > "organisation" instead of "Hospital" in the catalog. > > There must be a way to get it, cos when I view the catalog entry for the new > item, Type is "Hospital", but org_type stubbornly refuses to find that > value! Can someone please save me from pulling out any more hair? :-) > > Also, when creating a product, what's the best-practice for setting > "meta_type =" and "portal_type =" in the class? Some products use both, some > neither, some use one but not the other! > > TIA > > Cheers, Jon > > Jon Edwards > Pricom Ltd > www.pricom.co.uk > > > _______________________________________________ > Zope-CMF maillist - [EMAIL PROTECTED] > http://lists.zope.org/mailman/listinfo/zope-cmf > > See http://www.zope.org/Products/PTK/Tracker for bug reports and feature > requests > -- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 10 http://nuxeo.com mailto:[EMAIL PROTECTED] _______________________________________________ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )