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,13 +42,15 @@ from Products.ERP5Type.Globals import InitializeClass ...@@ -43,13 +42,15 @@ 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,
portal=None,
accessor_holder_module_name=None):
""" """
Create a new accessor holder class from the given Property Holder Create a new accessor holder class from the given Property Holder
within the given accessor holder module (when the migration will within the given accessor holder module
be finished, there should only be one accessor holder module)
""" """
property_sheet_id = property_holder.__name__ property_sheet_id = property_holder.__name__
setDefaultClassProperties(property_holder) setDefaultClassProperties(property_holder)
...@@ -67,7 +68,7 @@ def _createAccessorHolderFromPropertyHolder(property_holder, ...@@ -67,7 +68,7 @@ def _createAccessorHolderFromPropertyHolder(property_holder,
raise raise
# Create the new accessor holder class and set its module properly # Create the new accessor holder class and set its module properly
accessor_holder_class = type(property_sheet_id, (object,), dict( accessor_holder_class = meta_type(property_sheet_id, (object,), dict(
__module__ = accessor_holder_module_name, __module__ = accessor_holder_module_name,
constraints = property_holder.constraints, constraints = property_holder.constraints,
# The following attributes have been defined only because they # The following attributes have been defined only because they
...@@ -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