[Erp5-report] r42809 nicolas.dumazet - in /erp5/trunk/products/ERP5Type: Tool/ dynamic/
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Jan 31 13:55:48 CET 2011
Author: nicolas.dumazet
Date: Mon Jan 31 13:55:48 2011
New Revision: 42809
URL: http://svn.erp5.org?rev=42809&view=rev
Log:
AccessorHolderType meta class, and clear fromPropertyHolder factory
Modified:
erp5/trunk/products/ERP5Type/Tool/PropertySheetTool.py
erp5/trunk/products/ERP5Type/dynamic/accessor_holder.py
Modified: erp5/trunk/products/ERP5Type/Tool/PropertySheetTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Tool/PropertySheetTool.py?rev=42809&r1=42808&r2=42809&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Tool/PropertySheetTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Tool/PropertySheetTool.py [utf8] Mon Jan 31 13:55:48 2011
@@ -37,7 +37,7 @@ from Products.ERP5Type.Base import Prope
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.Expression import Expression
-from Products.ERP5Type.dynamic.accessor_holder import _createAccessorHolderFromPropertyHolder
+from Products.ERP5Type.dynamic.accessor_holder import AccessorHolderType
from zLOG import LOG, ERROR, INFO
@@ -191,7 +191,7 @@ class PropertySheetTool(BaseTool):
property_holder._categories = getattr(property_sheet, '_categories', [])
property_holder._constraints = getattr(property_sheet, '_constraints', [])
- return _createCommonPropertySheetAccessorHolder(
+ return AccessorHolderType.fromPropertyHolder(
self.getPortalObject(),
property_holder,
'erp5.filesystem_accessor_holder')
@@ -215,7 +215,7 @@ class PropertySheetTool(BaseTool):
property_holder._categories, \
property_holder._constraints = definition_tuple
- return _createAccessorHolderFromPropertyHolder(
+ return AccessorHolderType.fromPropertyHolder(
self.getPortalObject(),
property_holder,
'erp5.accessor_holder')
Modified: erp5/trunk/products/ERP5Type/dynamic/accessor_holder.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/dynamic/accessor_holder.py?rev=42809&r1=42808&r2=42809&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/dynamic/accessor_holder.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/dynamic/accessor_holder.py [utf8] Mon Jan 31 13:55:48 2011
@@ -29,8 +29,7 @@
This module should include most code related to the generation of
Accessor Holders, that is, generation of methods for ERP5
-* Ideally, PropertyHolder class should be defined here, as well
-as a base class for all erp5.accessor_holder Accessor Holders.
+* Ideally, PropertyHolder class should be defined here
* Utils, Property Sheet Tool can be probably be cleaned up as well by
moving specialized code here.
"""
@@ -43,65 +42,67 @@ from Products.ERP5Type.Globals import In
from zLOG import LOG, ERROR, INFO
-def _createAccessorHolderFromPropertyHolder(property_holder,
- portal,
- accessor_holder_module_name):
- """
- Create a new accessor holder class from the given Property Holder
- within the given accessor holder module (when the migration will
- be finished, there should only be one accessor holder module)
- """
- property_sheet_id = property_holder.__name__
- setDefaultClassProperties(property_holder)
-
- try:
- setDefaultProperties(property_holder,
- object=portal,
- portal=portal)
- except:
- LOG("Tool.PropertySheetTool", ERROR,
- "Could not generate accessor holder class for %s (module=%s)" % \
- (property_sheet_id, accessor_holder_module_name),
- error=sys.exc_info())
-
- raise
-
- # Create the new accessor holder class and set its module properly
- accessor_holder_class = type(property_sheet_id, (object,), dict(
- __module__ = accessor_holder_module_name,
- constraints = property_holder.constraints,
- # The following attributes have been defined only because they
- # are being used in ERP5Type.Utils when getting all the
- # property_sheets of the property_holder (then, they are added
- # to the local properties, categories and constraints lists)
- _properties = property_holder._properties,
- # Necessary for getBaseCategoryList
- _categories = property_holder._categories,
- _constraints = property_holder._constraints,
- security = property_holder.security
- ))
-
- # Set all the accessors (defined by a tuple) from the Property
- # Holder to the new accessor holder class (code coming from
- # createAccessor in Base.PropertyHolder)
- for id, fake_accessor in property_holder._getItemList():
- if not isinstance(fake_accessor, tuple):
- continue
-
- if fake_accessor is PropertyHolder.WORKFLOW_METHOD_MARKER:
- # Case 1 : a workflow method only
- accessor = Base._doNothing
- else:
- # Case 2 : a workflow method over an accessor
- (accessor_class, accessor_args, key) = fake_accessor
- accessor = accessor_class(id, key, *accessor_args)
-
- # Add the accessor to the accessor holder
- setattr(accessor_holder_class, id, accessor)
-
- property_holder.security.apply(accessor_holder_class)
- InitializeClass(accessor_holder_class)
- return accessor_holder_class
+class AccessorHolderType(type):
+ @classmethod
+ def fromPropertyHolder(meta_type,
+ property_holder,
+ portal=None,
+ accessor_holder_module_name=None):
+ """
+ Create a new accessor holder class from the given Property Holder
+ within the given accessor holder module
+ """
+ property_sheet_id = property_holder.__name__
+ setDefaultClassProperties(property_holder)
+
+ try:
+ setDefaultProperties(property_holder,
+ object=portal,
+ portal=portal)
+ except:
+ LOG("Tool.PropertySheetTool", ERROR,
+ "Could not generate accessor holder class for %s (module=%s)" % \
+ (property_sheet_id, accessor_holder_module_name),
+ error=sys.exc_info())
+
+ raise
+
+ # Create the new accessor holder class and set its module properly
+ accessor_holder_class = meta_type(property_sheet_id, (object,), dict(
+ __module__ = accessor_holder_module_name,
+ constraints = property_holder.constraints,
+ # The following attributes have been defined only because they
+ # are being used in ERP5Type.Utils when getting all the
+ # property_sheets of the property_holder (then, they are added
+ # to the local properties, categories and constraints lists)
+ _properties = property_holder._properties,
+ # Necessary for getBaseCategoryList
+ _categories = property_holder._categories,
+ _constraints = property_holder._constraints,
+ security = property_holder.security
+ ))
+
+ # Set all the accessors (defined by a tuple) from the Property
+ # Holder to the new accessor holder class (code coming from
+ # createAccessor in Base.PropertyHolder)
+ for id, fake_accessor in property_holder._getItemList():
+ if not isinstance(fake_accessor, tuple):
+ continue
+
+ if fake_accessor is PropertyHolder.WORKFLOW_METHOD_MARKER:
+ # Case 1 : a workflow method only
+ accessor = Base._doNothing
+ else:
+ # Case 2 : a workflow method over an accessor
+ (accessor_class, accessor_args, key) = fake_accessor
+ accessor = accessor_class(id, key, *accessor_args)
+
+ # Add the accessor to the accessor holder
+ setattr(accessor_holder_class, id, accessor)
+
+ property_holder.security.apply(accessor_holder_class)
+ InitializeClass(accessor_holder_class)
+ return accessor_holder_class
generating_base_accessors = False
@@ -136,7 +137,7 @@ def _generateBaseAccessorHolder(portal,
econtext,
base_category_list)
- accessor_holder = _createAccessorHolderFromPropertyHolder(
+ accessor_holder = AccessorHolderType.fromPropertyHolder(
property_holder,
portal,
'erp5.accessor_holder',
@@ -172,7 +173,7 @@ def _generatePreferenceToolAccessorHolde
if read_permission:
property_holder.declareProtected(read_permission, attribute_name)
- accessor_holder = _createAccessorHolderFromPropertyHolder(
+ accessor_holder = AccessorHolderType.fromPropertyHolder(
property_holder,
portal,
'erp5.accessor_holder',
More information about the Erp5-report
mailing list