Commit 3f990fa3 authored by Nicolas Dumazet's avatar Nicolas Dumazet

move/rename PropertySheetTool._createCommonPropertySheetAccessorHolder to

accessor_holder._createAccessorHolderFromPropertyHolder


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42805 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 94084e3e
...@@ -27,18 +27,17 @@ ...@@ -27,18 +27,17 @@
# #
############################################################################## ##############################################################################
import sys
import transaction import transaction
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Tool.BaseTool import BaseTool from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Type.Accessor import Translation from Products.ERP5Type.Accessor import Translation
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.Base import Base, PropertyHolder
from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.dynamic.accessor_holder import _createAccessorHolderFromPropertyHolder
from Products.ERP5Type.Utils import setDefaultClassProperties, setDefaultProperties
from zLOG import LOG, ERROR, INFO from zLOG import LOG, ERROR, INFO
...@@ -177,66 +176,6 @@ class PropertySheetTool(BaseTool): ...@@ -177,66 +176,6 @@ class PropertySheetTool(BaseTool):
return (properties, categories, constraints) return (properties, categories, constraints)
def _createCommonPropertySheetAccessorHolder(self,
property_holder,
property_sheet_id,
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)
"""
setDefaultClassProperties(property_holder)
try:
setDefaultProperties(property_holder,
object=self,
portal=self.getPortalObject())
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
security.declarePrivate('createFilesystemPropertySheetAccessorHolder') security.declarePrivate('createFilesystemPropertySheetAccessorHolder')
def createFilesystemPropertySheetAccessorHolder(self, property_sheet): def createFilesystemPropertySheetAccessorHolder(self, property_sheet):
""" """
...@@ -252,7 +191,8 @@ class PropertySheetTool(BaseTool): ...@@ -252,7 +191,8 @@ 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 self._createCommonPropertySheetAccessorHolder( return _createCommonPropertySheetAccessorHolder(
self.getPortalObject(),
property_holder, property_holder,
property_sheet.__name__, property_sheet.__name__,
'erp5.filesystem_accessor_holder') 'erp5.filesystem_accessor_holder')
...@@ -278,7 +218,8 @@ class PropertySheetTool(BaseTool): ...@@ -278,7 +218,8 @@ class PropertySheetTool(BaseTool):
property_sheet_name = property_sheet.getId() property_sheet_name = property_sheet.getId()
property_holder.__name__ = property_sheet_name property_holder.__name__ = property_sheet_name
return self._createCommonPropertySheetAccessorHolder( return _createAccessorHolderFromPropertyHolder(
self.getPortalObject(),
property_holder, property_holder,
property_sheet_name, property_sheet_name,
'erp5.accessor_holder') 'erp5.accessor_holder')
......
...@@ -34,12 +34,79 @@ as a base class for all erp5.accessor_holder Accessor Holders. ...@@ -34,12 +34,79 @@ 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.
""" """
from Products.ERP5Type.Base import PropertyHolder import sys
from Products.ERP5Type.Base import PropertyHolder, Base
from Products.ERP5Type.Utils import createRelatedAccessors, createExpressionContext from Products.ERP5Type.Utils import createRelatedAccessors, createExpressionContext
from Products.ERP5Type.Utils import setDefaultClassProperties, setDefaultProperties
from Products.ERP5Type.Globals import InitializeClass
from zLOG import LOG, ERROR, INFO
def _createAccessorHolderFromPropertyHolder(portal,
property_holder,
property_sheet_id,
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)
"""
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
generating_base_accessors = False generating_base_accessors = False
def _generateBaseAccessorHolder(portal, def _generateBaseAccessorHolder(portal,
property_sheet_tool, accessor_holder_module): accessor_holder_module):
base_accessor_holder_id = 'BaseAccessorHolder' base_accessor_holder_id = 'BaseAccessorHolder'
accessor_holder = getattr(accessor_holder_module, accessor_holder = getattr(accessor_holder_module,
...@@ -69,7 +136,8 @@ def _generateBaseAccessorHolder(portal, ...@@ -69,7 +136,8 @@ def _generateBaseAccessorHolder(portal,
econtext, econtext,
base_category_list) base_category_list)
accessor_holder = property_sheet_tool._createCommonPropertySheetAccessorHolder( accessor_holder = _createAccessorHolderFromPropertyHolder(
portal,
property_holder, property_holder,
base_accessor_holder_id, base_accessor_holder_id,
'erp5.accessor_holder', 'erp5.accessor_holder',
...@@ -78,8 +146,8 @@ def _generateBaseAccessorHolder(portal, ...@@ -78,8 +146,8 @@ def _generateBaseAccessorHolder(portal,
generating_base_accessors = False generating_base_accessors = False
return accessor_holder return accessor_holder
def _generatePreferenceToolAccessorHolder(accessor_holder_list, def _generatePreferenceToolAccessorHolder(portal, accessor_holder_list,
property_sheet_tool, accessor_holder_module): accessor_holder_module):
property_holder = PropertyHolder() property_holder = PropertyHolder()
from Products.ERP5Type.Accessor.TypeDefinition import list_types from Products.ERP5Type.Accessor.TypeDefinition import list_types
...@@ -105,7 +173,8 @@ def _generatePreferenceToolAccessorHolder(accessor_holder_list, ...@@ -105,7 +173,8 @@ def _generatePreferenceToolAccessorHolder(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 = property_sheet_tool._createCommonPropertySheetAccessorHolder( accessor_holder = _createAccessorHolderFromPropertyHolder(
portal,
property_holder, property_holder,
'PreferenceTool', 'PreferenceTool',
'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