Commit 32ab5744 authored by Nicolas Dumazet's avatar Nicolas Dumazet

add optional initialize parameter; and do not skip non-fake accessors


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42833 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 980a947a
...@@ -47,25 +47,28 @@ class AccessorHolderType(type): ...@@ -47,25 +47,28 @@ class AccessorHolderType(type):
def fromPropertyHolder(meta_type, def fromPropertyHolder(meta_type,
property_holder, property_holder,
portal=None, portal=None,
accessor_holder_module_name=None): accessor_holder_module_name=None,
initialize=True):
""" """
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 within the given accessor holder module
""" """
property_sheet_id = property_holder.__name__ property_sheet_id = property_holder.__name__
setDefaultClassProperties(property_holder) context = portal.portal_property_sheets
if initialize:
try: setDefaultClassProperties(property_holder)
setDefaultProperties(property_holder,
object=portal, try:
portal=portal) setDefaultProperties(property_holder,
except: object=context,
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())
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 = meta_type(property_sheet_id, (object,), dict( accessor_holder_class = meta_type(property_sheet_id, (object,), dict(
...@@ -86,6 +89,10 @@ class AccessorHolderType(type): ...@@ -86,6 +89,10 @@ class AccessorHolderType(type):
# Holder to the new accessor holder class (code coming from # Holder to the new accessor holder class (code coming from
# createAccessor in Base.PropertyHolder) # createAccessor in Base.PropertyHolder)
for id, fake_accessor in property_holder._getPropertyHolderItemList(): for id, fake_accessor in property_holder._getPropertyHolderItemList():
if callable(fake_accessor):
# not so fake ;)
setattr(accessor_holder_class, id, fake_accessor)
continue
if not isinstance(fake_accessor, tuple): if not isinstance(fake_accessor, tuple):
continue continue
...@@ -131,7 +138,7 @@ def _generateBaseAccessorHolder(portal, ...@@ -131,7 +138,7 @@ def _generateBaseAccessorHolder(portal,
property_holder = PropertyHolder(base_accessor_holder_id) property_holder = PropertyHolder(base_accessor_holder_id)
econtext = createExpressionContext(portal, portal) econtext = createExpressionContext(portal_categories, portal)
createRelatedAccessors(portal_categories, createRelatedAccessors(portal_categories,
property_holder, property_holder,
econtext, econtext,
...@@ -141,7 +148,7 @@ def _generateBaseAccessorHolder(portal, ...@@ -141,7 +148,7 @@ def _generateBaseAccessorHolder(portal,
property_holder, property_holder,
portal, portal,
'erp5.accessor_holder', 'erp5.accessor_holder',
skip_default=True) initialize=False)
setattr(accessor_holder_module, base_accessor_holder_id, accessor_holder) setattr(accessor_holder_module, base_accessor_holder_id, accessor_holder)
generating_base_accessors = False generating_base_accessors = False
return accessor_holder return accessor_holder
...@@ -177,7 +184,7 @@ def _generatePreferenceToolAccessorHolder(portal, accessor_holder_list, ...@@ -177,7 +184,7 @@ def _generatePreferenceToolAccessorHolder(portal, accessor_holder_list,
property_holder, property_holder,
portal, portal,
'erp5.accessor_holder', 'erp5.accessor_holder',
skip_default=True) initialize=False)
setattr(accessor_holder_module, 'PreferenceTool', accessor_holder) setattr(accessor_holder_module, 'PreferenceTool', accessor_holder)
return accessor_holder return 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