From 20471c58f40776ed731797ac5bd01b19484db700 Mon Sep 17 00:00:00 2001
From: Jean-Paul Smets <jp@nexedi.com>
Date: Sun, 12 Aug 2007 18:35:35 +0000
Subject: [PATCH] Added getPropertySheetPropertyIdList to ClassTool. This is
 useful for example to check if the ID of a category is the same as a property
 ID.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15616 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/Tool/ClassTool.py | 35 +++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/product/ERP5Type/Tool/ClassTool.py b/product/ERP5Type/Tool/ClassTool.py
index eac64848b8..1e6a5fc411 100644
--- a/product/ERP5Type/Tool/ClassTool.py
+++ b/product/ERP5Type/Tool/ClassTool.py
@@ -60,6 +60,8 @@ from Products.ERP5Type.Base import newTempDocumentationHelper
 
 from Products.ERP5Type import allowClassTool
 
+import Products
+
 from zLOG import LOG
 
 """
@@ -76,6 +78,33 @@ from zLOG import LOG
 COPYRIGHT = "Copyright (c) 2002-2007 Nexedi SARL and Contributors. All Rights Reserved."
 LOCAL_DIRECTORY_LIST = ('Document', 'Extensions', 'Constraint', 'tests', 'PropertySheet')
 
+
+class ClassToolMixIn:
+  """
+    Provides common methods which portal_classes should always provide
+  """
+  # Declarative Security
+  security = ClassSecurityInfo()
+
+  security.declareProtected( Permissions.ManagePortal, 'getPropertySheetPropertyIdList' )
+  def getPropertySheetPropertyIdList(self):
+    """
+    Returns the sorted list of property IDs defined in the current instance
+    in global and local property sheets
+    """
+    property_sheet_name_list = Products.ERP5Type.PropertySheet.__dict__.keys()
+    property_sheet_name_list = filter(lambda k: not k.startswith('__'),  property_sheet_name_list)
+    result_dict = {}
+    for property_sheet_name in property_sheet_name_list:
+      for property in getattr(getattr(Products.ERP5Type.PropertySheet, property_sheet_name),
+                              '_properties', ()):
+        result_dict[property['id']] = None
+        if property.has_key('storage_id'):
+          result_dict[property['storage_id']] = None
+    result = result_dict.keys()
+    result.sort()
+    return result
+
 if allowClassTool():
 
   class TemporaryInstanceHome(TM):
@@ -115,7 +144,7 @@ if allowClassTool():
     def _abort(self):
       shutil.rmtree(self.path, 1)
 
-  class ClassTool(BaseTool):
+  class ClassTool(BaseTool, ClassToolMixIn):
       """
         This is the full-featured version of ClassTool.
       """
@@ -832,7 +861,7 @@ def initialize( context ):
                                  'asDocumentationHelper')
       def asDocumentationHelper(self, class_id):
         """
-          This funciton generates a TempDocumentationHelper for a class of a
+          This function generates a TempDocumentationHelper for a class of a
           given name.
 
           XXX: this code is (almost) duplicated from ERP5Types/Base.py:asDocumentationHelper
@@ -922,7 +951,7 @@ def initialize( context ):
 
 else:
 
-  class ClassTool(BaseTool):
+  class ClassTool(BaseTool, ClassToolMixIn):
       """
         Dummy version of ClassTool.
       """
-- 
2.30.9