Commit 2fa7eb24 authored by Nicolas Dumazet's avatar Nicolas Dumazet

AccessorHolderType meta class, and clear fromPropertyHolder factory


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42809 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f8cba738
...@@ -37,7 +37,7 @@ from Products.ERP5Type.Base import PropertyHolder ...@@ -37,7 +37,7 @@ from Products.ERP5Type.Base import PropertyHolder
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.CMFCore.Expression import Expression 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 from zLOG import LOG, ERROR, INFO
...@@ -191,7 +191,7 @@ class PropertySheetTool(BaseTool): ...@@ -191,7 +191,7 @@ class PropertySheetTool(BaseTool):
property_holder._categories = getattr(property_sheet, '_categories', []) property_holder._categories = getattr(property_sheet, '_categories', [])
property_holder._constraints = getattr(property_sheet, '_constraints', []) property_holder._constraints = getattr(property_sheet, '_constraints', [])
return _createCommonPropertySheetAccessorHolder( return AccessorHolderType.fromPropertyHolder(
self.getPortalObject(), self.getPortalObject(),
property_holder, property_holder,
'erp5.filesystem_accessor_holder') 'erp5.filesystem_accessor_holder')
...@@ -215,7 +215,7 @@ class PropertySheetTool(BaseTool): ...@@ -215,7 +215,7 @@ class PropertySheetTool(BaseTool):
property_holder._categories, \ property_holder._categories, \
property_holder._constraints = definition_tuple property_holder._constraints = definition_tuple
return _createAccessorHolderFromPropertyHolder( return AccessorHolderType.fromPropertyHolder(
self.getPortalObject(), self.getPortalObject(),
property_holder, property_holder,
'erp5.accessor_holder') 'erp5.accessor_holder')
......
...@@ -29,8 +29,7 @@ ...@@ -29,8 +29,7 @@
This module should include most code related to the generation of This module should include most code related to the generation of
Accessor Holders, that is, generation of methods for ERP5 Accessor Holders, that is, generation of methods for ERP5
* Ideally, PropertyHolder class should be defined here, as well * Ideally, PropertyHolder class should be defined here
as a base class for all erp5.accessor_holder Accessor Holders.
* Utils, Property Sheet Tool can be probably be cleaned up as well by * Utils, Property Sheet Tool can be probably be cleaned up as well by
moving specialized code here. moving specialized code here.
""" """
...@@ -43,65 +42,67 @@ from Products.ERP5Type.Globals import InitializeClass ...@@ -43,65 +42,67 @@ from Products.ERP5Type.Globals import InitializeClass
from zLOG import LOG, ERROR, INFO from zLOG import LOG, ERROR, INFO
def _createAccessorHolderFromPropertyHolder(property_holder, class AccessorHolderType(type):
portal, @classmethod
accessor_holder_module_name): def fromPropertyHolder(meta_type,
""" property_holder,
Create a new accessor holder class from the given Property Holder portal=None,
within the given accessor holder module (when the migration will accessor_holder_module_name=None):
be finished, there should only be one accessor holder module) """
""" Create a new accessor holder class from the given Property Holder
property_sheet_id = property_holder.__name__ within the given accessor holder module
setDefaultClassProperties(property_holder) """
property_sheet_id = property_holder.__name__
try: setDefaultClassProperties(property_holder)
setDefaultProperties(property_holder,
object=portal, try:
portal=portal) setDefaultProperties(property_holder,
except: object=portal,
LOG("Tool.PropertySheetTool", ERROR, portal=portal)
"Could not generate accessor holder class for %s (module=%s)" % \ except:
(property_sheet_id, accessor_holder_module_name), LOG("Tool.PropertySheetTool", ERROR,
error=sys.exc_info()) "Could not generate accessor holder class for %s (module=%s)" % \
(property_sheet_id, accessor_holder_module_name),
raise error=sys.exc_info())
# Create the new accessor holder class and set its module properly raise
accessor_holder_class = type(property_sheet_id, (object,), dict(
__module__ = accessor_holder_module_name, # Create the new accessor holder class and set its module properly
constraints = property_holder.constraints, accessor_holder_class = meta_type(property_sheet_id, (object,), dict(
# The following attributes have been defined only because they __module__ = accessor_holder_module_name,
# are being used in ERP5Type.Utils when getting all the constraints = property_holder.constraints,
# property_sheets of the property_holder (then, they are added # The following attributes have been defined only because they
# to the local properties, categories and constraints lists) # are being used in ERP5Type.Utils when getting all the
_properties = property_holder._properties, # property_sheets of the property_holder (then, they are added
# Necessary for getBaseCategoryList # to the local properties, categories and constraints lists)
_categories = property_holder._categories, _properties = property_holder._properties,
_constraints = property_holder._constraints, # Necessary for getBaseCategoryList
security = property_holder.security _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) # Set all the accessors (defined by a tuple) from the Property
for id, fake_accessor in property_holder._getItemList(): # Holder to the new accessor holder class (code coming from
if not isinstance(fake_accessor, tuple): # createAccessor in Base.PropertyHolder)
continue for id, fake_accessor in property_holder._getItemList():
if not isinstance(fake_accessor, tuple):
if fake_accessor is PropertyHolder.WORKFLOW_METHOD_MARKER: continue
# Case 1 : a workflow method only
accessor = Base._doNothing if fake_accessor is PropertyHolder.WORKFLOW_METHOD_MARKER:
else: # Case 1 : a workflow method only
# Case 2 : a workflow method over an accessor accessor = Base._doNothing
(accessor_class, accessor_args, key) = fake_accessor else:
accessor = accessor_class(id, key, *accessor_args) # Case 2 : a workflow method over an accessor
(accessor_class, accessor_args, key) = fake_accessor
# Add the accessor to the accessor holder accessor = accessor_class(id, key, *accessor_args)
setattr(accessor_holder_class, id, accessor)
# Add the accessor to the accessor holder
property_holder.security.apply(accessor_holder_class) setattr(accessor_holder_class, id, accessor)
InitializeClass(accessor_holder_class)
return accessor_holder_class property_holder.security.apply(accessor_holder_class)
InitializeClass(accessor_holder_class)
return accessor_holder_class
generating_base_accessors = False generating_base_accessors = False
...@@ -136,7 +137,7 @@ def _generateBaseAccessorHolder(portal, ...@@ -136,7 +137,7 @@ def _generateBaseAccessorHolder(portal,
econtext, econtext,
base_category_list) base_category_list)
accessor_holder = _createAccessorHolderFromPropertyHolder( accessor_holder = AccessorHolderType.fromPropertyHolder(
property_holder, property_holder,
portal, portal,
'erp5.accessor_holder', 'erp5.accessor_holder',
...@@ -172,7 +173,7 @@ def _generatePreferenceToolAccessorHolder(portal, accessor_holder_list, ...@@ -172,7 +173,7 @@ def _generatePreferenceToolAccessorHolder(portal, accessor_holder_list,
if read_permission: if read_permission:
property_holder.declareProtected(read_permission, attribute_name) property_holder.declareProtected(read_permission, attribute_name)
accessor_holder = _createAccessorHolderFromPropertyHolder( accessor_holder = AccessorHolderType.fromPropertyHolder(
property_holder, property_holder,
portal, portal,
'erp5.accessor_holder', 'erp5.accessor_holder',
......
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