Commit 3cb69cdf authored by Nicolas Dumazet's avatar Nicolas Dumazet

getPortalTypeClass: simple API to retrieve a portal type class from a portal

type string, from an existing object, or from an existing class.

This is meant to be the high-level API to manipulate classes, and noone should
be seen using something else ;)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38664 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 96bfc618
...@@ -169,6 +169,34 @@ class TypesTool(TypeProvider): ...@@ -169,6 +169,34 @@ class TypesTool(TypeProvider):
from Products.ERP5Type import document_class_registry from Products.ERP5Type import document_class_registry
return sorted(document_class_registry) return sorted(document_class_registry)
security.declareProtected(Permissions.AccessContentsInformation, 'getPortalTypeClass')
def getPortalTypeClass(self, context, temp=False):
"""
Infer a portal type class from the context.
Context can be a portal type string, or an object, or a class.
This is the proper API to retrieve a portal type class, and no one
should hack anything anywhere else.
"""
portal_type = None
if isinstance(context, type):
if 'erp5' in context.__module__:
portal_type = context.__name__
else:
portal_type = getattr(context, 'portal_type', None)
elif isinstance(context, str):
portal_type = context
else:
portal_type = getattr(context, 'portal_type', None)
if portal_type is not None:
import erp5
if temp:
module = erp5.temp_portal_type
else:
module = erp5.portal_type
return getattr(module, portal_type, None)
security.declareProtected(Permissions.AccessContentsInformation, 'getMixinTypeList') security.declareProtected(Permissions.AccessContentsInformation, 'getMixinTypeList')
def getMixinTypeList(self): def getMixinTypeList(self):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment