[Erp5-report] r9094 - /erp5/trunk/products/ERP5Type/ERP5Type.py

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Aug 9 10:20:49 CEST 2006


Author: chris
Date: Wed Aug  9 10:20:39 2006
New Revision: 9094

URL: http://svn.erp5.org?rev=9094&view=rev
Log:
- Added a function that returns the properties AND the categories of a portal type

Modified:
    erp5/trunk/products/ERP5Type/ERP5Type.py

Modified: erp5/trunk/products/ERP5Type/ERP5Type.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/ERP5Type.py?rev=9094&r1=9093&r2=9094&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/ERP5Type.py (original)
+++ erp5/trunk/products/ERP5Type/ERP5Type.py Wed Aug  9 10:20:39 2006
@@ -30,7 +30,7 @@
 from Products.CMFCore.ActionProviderBase import ActionProviderBase
 from Products.CMFCore.utils import SimpleItemWithProperties
 from Products.CMFCore.Expression import createExprContext
-
+from Products.ERP5Type import PropertySheet
 from Products.ERP5Type import _dtmldir
 from Products.ERP5Type import Permissions as ERP5Permissions
 
@@ -243,6 +243,48 @@
         return self.defined_group_list
 
     security.declareProtected(ERP5Permissions.AccessContentsInformation,
+		              'getPropertiesAndCategories')
+    def getPropertiesAndCategories(self):
+      """
+       Return all the properties and categories of
+       the portal type
+      """
+      ptype_object = self
+      # get the klass of the object based on the constructor document
+      m = Products.ERP5Type._m
+      ptype_name = ''.join(ptype_object.id.split(' '))
+      constructor = 'add%s' %(ptype_name)
+      klass = None
+      for method, doc in m.items():
+        if method == constructor:
+          klass = doc.klass
+          break
+      # get the property sheet list for the portal type
+      # from the list of property sheet defined on the portal type
+      ps_list = map(lambda p: getattr(PropertySheet, p, None),
+                  ptype_object.property_sheet_list)
+      ps_list = filter(lambda p: p is not None, ps_list)
+      # from the property sheets defined on the class
+      if klass is not None:
+        from Products.ERP5Type.Base import getClassPropertyList
+        ps_list = tuple(ps_list) + getClassPropertyList(klass)
+      # get all properties from the property sheet list
+      current_list = []
+      for base in ps_list:
+	ps_property = getattr(base, '_properties', None)
+        if type(ps_property) in (type(()), type([])):
+          for prop in ps_property:
+            if prop['id'] not in current_list:
+	      current_list.append(prop['id'])
+        ps_property = getattr(base, '_categories', None)
+	if type(ps_property) in (type(()), type([])):
+	  cat_dict_list = []
+	  for category in ps_property:
+	    if category not in current_list:
+              current_list.append(category)
+      return current_list
+
+    security.declareProtected(ERP5Permissions.AccessContentsInformation,
                               'getInstancePropertyMap' )
     def getInstancePropertyMap(self):
       """




More information about the Erp5-report mailing list