[Erp5-report] r38664 nicolas.dumazet - /erp5/trunk/products/ERP5Type/Tool/TypesTool.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Sep 27 14:42:30 CEST 2010
Author: nicolas.dumazet
Date: Mon Sep 27 14:42:28 2010
New Revision: 38664
URL: http://svn.erp5.org?rev=38664&view=rev
Log:
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 ;)
Modified:
erp5/trunk/products/ERP5Type/Tool/TypesTool.py
Modified: erp5/trunk/products/ERP5Type/Tool/TypesTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Tool/TypesTool.py?rev=38664&r1=38663&r2=38664&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Tool/TypesTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Tool/TypesTool.py [utf8] Mon Sep 27 14:42:28 2010
@@ -169,6 +169,34 @@ class TypesTool(TypeProvider):
from Products.ERP5Type import 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')
def getMixinTypeList(self):
"""
More information about the Erp5-report
mailing list