Commit df21810e authored by Arnaud Fontaine's avatar Arnaud Fontaine

Refactor portal_type_class so that all accessor holder classes are

associated to a portal type class in the same function



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43118 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8913d816
...@@ -33,8 +33,8 @@ import inspect ...@@ -33,8 +33,8 @@ import inspect
from types import ModuleType from types import ModuleType
from dynamic_module import registerDynamicModule from dynamic_module import registerDynamicModule
from accessor_holder import _generateBaseAccessorHolder, _generatePreferenceToolAccessorHolder from accessor_holder import _generateBaseAccessorHolder, \
_generatePreferenceToolAccessorHolder
from Products.ERP5Type.mixin.temporary import TemporaryDocumentMixin from Products.ERP5Type.mixin.temporary import TemporaryDocumentMixin
from Products.ERP5Type.Base import Base, resetRegisteredWorkflowMethod from Products.ERP5Type.Base import Base, resetRegisteredWorkflowMethod
...@@ -58,30 +58,45 @@ def _importClass(classpath): ...@@ -58,30 +58,45 @@ def _importClass(classpath):
except StandardError: except StandardError:
raise ImportError('Could not import document class %s' % classpath) raise ImportError('Could not import document class %s' % classpath)
def _fillAccessorHolderList(accessor_holder_list, def _createAccessorHolderList(site,
create_accessor_holder_func, portal_type_name,
property_sheet_name_set, property_sheet_name_set):
accessor_holder_module,
property_sheet_module):
""" """
Fill the accessor holder list with the given Property Sheets (which Create the accessor holder list with the given ZODB Property Sheets
could be coming either from the filesystem or ZODB)
""" """
import erp5.accessor_holder
property_sheet_tool = site.portal_property_sheets
accessor_holder_list = []
if "Base" in property_sheet_name_set:
accessor_holder_class = None
# useless if Base Category is not yet here or if we're currently
# generating accessors for Base Categories
if hasattr(erp5.accessor_holder, "BaseCategory"):
accessor_holder_class = _generateBaseAccessorHolder(site,
erp5.accessor_holder)
if accessor_holder_class is not None:
accessor_holder_list.append(accessor_holder_class)
for property_sheet_name in property_sheet_name_set: for property_sheet_name in property_sheet_name_set:
# LOG("ERP5Type.dynamic", INFO, # LOG("ERP5Type.dynamic", INFO,
# "Getting accessor holder for " + property_sheet_name) # "Getting accessor holder for " + property_sheet_name)
try: try:
# Get the already generated accessor holder # Get the already generated accessor holder
accessor_holder_list.append(getattr(accessor_holder_module, accessor_holder_list.append(getattr(erp5.accessor_holder,
property_sheet_name)) property_sheet_name))
except AttributeError: except AttributeError:
# Generate the accessor holder as it has not been done yet # Generate the accessor holder as it has not been done yet
try: try:
accessor_holder_class = \ accessor_holder_class = \
create_accessor_holder_func(getattr(property_sheet_module, property_sheet_tool.createZodbPropertySheetAccessorHolder(
property_sheet_name)) getattr(property_sheet_tool,
property_sheet_name))
except AttributeError: except AttributeError:
LOG("ERP5Type.dynamic", ERROR, LOG("ERP5Type.dynamic", ERROR,
...@@ -91,15 +106,25 @@ def _fillAccessorHolderList(accessor_holder_list, ...@@ -91,15 +106,25 @@ def _fillAccessorHolderList(accessor_holder_list,
accessor_holder_list.append(accessor_holder_class) accessor_holder_list.append(accessor_holder_class)
setattr(accessor_holder_module, property_sheet_name, setattr(erp5.accessor_holder, property_sheet_name,
accessor_holder_class) accessor_holder_class)
# LOG("ERP5Type.dynamic", INFO, # LOG("ERP5Type.dynamic", INFO,
# "Created accessor holder for %s in %s" % (property_sheet_name, # "Created accessor holder for %s" % property_sheet_name)
# accessor_holder_module))
# LOG("ERP5Type.dynamic", INFO, # XXX a hook to add per-portal type accessor holders maybe?
# "Got accessor holder for " + property_sheet_name) if portal_type_name == "Preference Tool":
accessor_holder_class = \
_generatePreferenceToolAccessorHolder(site,
accessor_holder_list,
erp5.accessor_holder)
accessor_holder_list.insert(0, accessor_holder_class)
# LOG("ERP5Type.dynamic", INFO,
# "Got accessor holder for %s: %s" % (property_sheet_name, accessor_holder_list))
return accessor_holder_list
# Loading Cache Factory portal type would generate the accessor holder # Loading Cache Factory portal type would generate the accessor holder
# for Cache Factory, itself defined with Standard Property thus # for Cache Factory, itself defined with Standard Property thus
...@@ -243,7 +268,7 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -243,7 +268,7 @@ def generatePortalTypeClass(site, portal_type_name):
property_sheet_tool = getattr(site, 'portal_property_sheets', None) property_sheet_tool = getattr(site, 'portal_property_sheets', None)
property_sheet_set = set() property_sheet_name_set = set()
# The Property Sheet Tool may be None if the code is updated but # The Property Sheet Tool may be None if the code is updated but
# the BT has not been upgraded yet with portal_property_sheets # the BT has not been upgraded yet with portal_property_sheets
...@@ -252,16 +277,15 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -252,16 +277,15 @@ def generatePortalTypeClass(site, portal_type_name):
LOG("ERP5Type.dynamic", WARNING, LOG("ERP5Type.dynamic", WARNING,
"Property Sheet Tool was not found. Please update erp5_core " "Property Sheet Tool was not found. Please update erp5_core "
"Business Template") "Business Template")
zodb_property_sheet_set = set() zodb_property_sheet_name_set = set()
else: else:
zodb_property_sheet_set = set(property_sheet_tool.objectIds()) zodb_property_sheet_name_set = set(property_sheet_tool.objectIds())
if portal_type is not None: if portal_type is not None:
# Get the Property Sheets defined on the portal_type and use the # Get the Property Sheets defined on the portal_type and use the
# ZODB Property Sheet rather than the filesystem only if it # ZODB Property Sheet rather than the filesystem
# exists in ZODB
for property_sheet in portal_type.getTypePropertySheetList(): for property_sheet in portal_type.getTypePropertySheetList():
if property_sheet in zodb_property_sheet_set: if property_sheet in zodb_property_sheet_name_set:
property_sheet_set.add(property_sheet) property_sheet_name_set.add(property_sheet)
# XXX maybe this should be a generic hook, adding property sheets # XXX maybe this should be a generic hook, adding property sheets
# dynamically for a given portal type name? If done well, this # dynamically for a given portal type name? If done well, this
...@@ -269,13 +293,12 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -269,13 +293,12 @@ def generatePortalTypeClass(site, portal_type_name):
if portal_type_name in ("Preference Tool", if portal_type_name in ("Preference Tool",
"Preference", "Preference",
"System Preference"): "System Preference"):
for property_sheet in zodb_property_sheet_set: for property_sheet in zodb_property_sheet_name_set:
if property_sheet.endswith('Preference'): if property_sheet.endswith('Preference'):
property_sheet_set.add(property_sheet) property_sheet_name_set.add(property_sheet)
# Get the Property Sheets defined on the document and its bases # Get the Property Sheets defined on the document and its bases
# recursively. Fallback on the filesystem Property Sheet only and # recursively
# only if the ZODB Property Sheet does not exist
from Products.ERP5Type.Base import getClassPropertyList from Products.ERP5Type.Base import getClassPropertyList
for property_sheet in getClassPropertyList(klass): for property_sheet in getClassPropertyList(klass):
# If the Property Sheet is a string, then this is a ZODB # If the Property Sheet is a string, then this is a ZODB
...@@ -285,38 +308,14 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -285,38 +308,14 @@ def generatePortalTypeClass(site, portal_type_name):
# string from now on # string from now on
if not isinstance(property_sheet, basestring): if not isinstance(property_sheet, basestring):
property_sheet = property_sheet.__name__ property_sheet = property_sheet.__name__
if property_sheet in zodb_property_sheet_set: if property_sheet in zodb_property_sheet_name_set:
property_sheet_set.add(property_sheet) property_sheet_name_set.add(property_sheet)
import erp5
if property_sheet_set:
if "Base" in property_sheet_set:
accessor_holder = None
# useless if Base Category is not yet here
# or if we're currently generating accessors for Base Categories
if hasattr(erp5.accessor_holder, "BaseCategory"):
accessor_holder = _generateBaseAccessorHolder(
site,
erp5.accessor_holder)
if accessor_holder is not None:
accessor_holder_list.append(accessor_holder)
if property_sheet_name_set:
# Initialize ZODB Property Sheets accessor holders # Initialize ZODB Property Sheets accessor holders
_fillAccessorHolderList( accessor_holder_list = _createAccessorHolderList(site,
accessor_holder_list, portal_type_name,
property_sheet_tool.createZodbPropertySheetAccessorHolder, property_sheet_name_set)
property_sheet_set,
erp5.accessor_holder,
property_sheet_tool)
# XXX a hook to add per-portal type accessor holders maybe?
if portal_type_name == "Preference Tool":
accessor_holder = _generatePreferenceToolAccessorHolder(
site,
accessor_holder_list,
erp5.accessor_holder)
accessor_holder_list.insert(0, accessor_holder)
base_category_set = set(attribute_dict['_categories']) base_category_set = set(attribute_dict['_categories'])
for accessor_holder in accessor_holder_list: for accessor_holder in accessor_holder_list:
...@@ -427,7 +426,6 @@ def synchronizeDynamicModules(context, force=False): ...@@ -427,7 +426,6 @@ def synchronizeDynamicModules(context, force=False):
return return
last_sync = cookie last_sync = cookie
import erp5 import erp5
Base.aq_method_lock.acquire() Base.aq_method_lock.acquire()
......
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