[Product-Developers] Re: From a portal_type to the python class

Raphael Ritz r.ritz at biologie.hu-berlin.de
Thu Jul 16 10:02:00 UTC 2009


Giovanni Toffoli wrote:
> Hi all,
> 
> I'm not able to find a clean way to get the class (the class object, not 
> only its name) implementing a portal_type.
> 
> In the past I followed a dirty approach, based on the portal_types tool 
> and relying on the assumptions that
> - the name of the class was the same than the name of the portal type
> - each class was defined in a separate module, with the same name than 
> the portal type, in the product registering the portal type.
> 
> I suppose that a more general method is available. Could somebody help me?
> TIA.

Not sure this helps but if you have an instance of the type
you can do the following (dump from a debug session, 'contentdemo'
is a Plone site in my current dev env)

 >>> site = app.contentdemo
 >>> site
<PloneSite at /contentdemo>
 >>> site.__class__
<class 'Products.CMFPlone.Portal.PloneSite'>
 >>> site.__class__.__base__
<class 'Products.CMFDefault.Portal.CMFSite'>
 >>> site.__class__.__bases__
(<class 'Products.CMFDefault.Portal.CMFSite'>, <class 
'Products.CMFPlone.PloneFolder.OrderedContainer'>, <class 
'Products.CMFDynamicViewFTI.browserdefault.BrowserDefaultMixin'>)
 >>>

and further on

 >>> about = site.about
 >>> about
<ATFolder at /contentdemo/about>
 >>> b = about.__class__.__bases__
 >>> b
(<class 'Products.ATContentTypes.lib.autosort.AutoOrderSupport'>, <class 
'Products.ATContentTypes.content.base.ATCTOrderedFolder'>)
 >>> of = b[1]
 >>> of
<class 'Products.ATContentTypes.content.base.ATCTOrderedFolder'>
 >>> of.schema
<Products.Archetypes.Schema.Schema object at 0x90a29ac>
 >>> of.schema.fields()
[<Field id(string:rw)>, <Field title(string:rw)>, <Field 
description(text:rw)>, <Field subject(lines:rw)>, <Field 
relatedItems(reference:rw)>, <Field location(string:rw)>, <Field 
language(string:rw)>, <Field effectiveDate(datetime:rw)>, <Field 
expirationDate(datetime:rw)>, <Field creation_date(datetime:rw)>, <Field 
modification_date(datetime:rw)>, <Field creators(lines:rw)>, <Field 
contributors(lines:rw)>, <Field rights(text:rw)>, <Field 
allowDiscussion(boolean:rw)>, <Field excludeFromNav(boolean:rw)>]
 >>>



Raphael


> 
> Giovanni Toffoli





More information about the Product-Developers mailing list