Commit 5618426a authored by Arnaud Fontaine's avatar Arnaud Fontaine

Fix loading of Base Type and Types Tool portal types once they have

been migrated to portal types class



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40287 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 315b548c
...@@ -93,6 +93,23 @@ def _fillAccessorHolderList(accessor_holder_list, ...@@ -93,6 +93,23 @@ def _fillAccessorHolderList(accessor_holder_list,
"Created accessor holder for %s in %s" % (property_sheet_name, "Created accessor holder for %s in %s" % (property_sheet_name,
accessor_holder_module)) accessor_holder_module))
# 'Types Tool' is required to access 'site.portal_types' and the
# former requires 'Base Type'. Thus, 'generating' is meaningful to
# avoid infinite recursion, whereas 'type_class' avoids accessing to
# portal_type
#
# For example, loading 'Types Tool' will try to load 'Types Tool' when
# accessing 'site.portal_types'. Therefore the inner one is just an
# import of 'Types Tool' class without any mixin, interface or
# Property Sheet to allow the outer (which will actually be stored in
# 'erp5.portal_type') to be fully generated.
core_portal_type_class_dict = {
'Base Type': {'type_class': 'ERP5TypeInformation',
'generating': False},
'Types Tool': {'type_class': 'TypesTool',
'generating': False}
}
def generatePortalTypeClass(portal_type_name): def generatePortalTypeClass(portal_type_name):
""" """
Given a portal type, look up in Types Tool the corresponding Given a portal type, look up in Types Tool the corresponding
...@@ -103,22 +120,48 @@ def generatePortalTypeClass(portal_type_name): ...@@ -103,22 +120,48 @@ def generatePortalTypeClass(portal_type_name):
from Products.ERP5.ERP5Site import getSite from Products.ERP5.ERP5Site import getSite
site = getSite() site = getSite()
accessor_holder_list = [] global core_portal_type_class_dict
type_class = None
if portal_type_name in core_portal_type_class_dict:
if not core_portal_type_class_dict[portal_type_name]['generating']:
# Loading the (full) outer portal type class
core_portal_type_class_dict[portal_type_name]['generating'] = True
else:
# Loading the inner portal type class without any mixin,
# interface or Property Sheet
klass = _importClass(document_class_registry.get(
core_portal_type_class_dict[portal_type_name]['type_class']))
# Don't do anything else, just allow to load fully the outer
# portal type class
return ((klass,), [], {})
# Do not use __getitem__ (or _getOb) because portal_type may exist in a # Do not use __getitem__ (or _getOb) because portal_type may exist in a
# type provider other than Types Tool. # type provider other than Types Tool.
portal_type = getattr(site.portal_types, portal_type_name, None) portal_type = getattr(site.portal_types, portal_type_name, None)
type_class = None
if portal_type is not None: if portal_type is not None:
# type_class has a compatibility getter that should return # type_class has a compatibility getter that should return
# something even if the field is not set (i.e. Base Type object # something even if the field is not set (i.e. Base Type object
# was not migrated yet). It only works if factory_method_id is set. # was not migrated yet). It only works if factory_method_id is set.
type_class = portal_type.getTypeClass() type_class = portal_type.getTypeClass()
# The Tools used to have 'Folder' or None as type_class instead of
# 'NAME Tool', so make sure the type_class is correct
#
# NOTE: under discussion so might be removed later on
if portal_type_name.endswith('Tool') and type_class in ('Folder', None):
type_class = portal_type_name.replace(' ', '')
mixin_list = portal_type.getTypeMixinList() mixin_list = portal_type.getTypeMixinList()
interface_list = portal_type.getTypeInterfaceList() interface_list = portal_type.getTypeInterfaceList()
# But if neither factory_init_method_id nor type_class are set on # But if neither factory_init_method_id nor type_class are set on
# the portal type, we have to try to guess, for compatibility # the portal type, we have to try to guess, for compatibility.
# Moreover, some tools, such as 'Activity Tool', don't have any
# portal type
if type_class is None: if type_class is None:
# Try to figure out a coresponding document class from the document side. # Try to figure out a coresponding document class from the document side.
# This can happen when calling newTempAmount for instance: # This can happen when calling newTempAmount for instance:
...@@ -141,6 +184,8 @@ def generatePortalTypeClass(portal_type_name): ...@@ -141,6 +184,8 @@ def generatePortalTypeClass(portal_type_name):
klass = _importClass(type_class_path) klass = _importClass(type_class_path)
accessor_holder_list = []
## Disabled because there will be no commit of ## Disabled because there will be no commit of
## type_zodb_property_sheet, only use for testing ATM ## type_zodb_property_sheet, only use for testing ATM
...@@ -191,6 +236,9 @@ def generatePortalTypeClass(portal_type_name): ...@@ -191,6 +236,9 @@ def generatePortalTypeClass(portal_type_name):
interface_class_list = [getattr(interfaces, name) interface_class_list = [getattr(interfaces, name)
for name in interface_list] for name in interface_list]
if portal_type_name in core_portal_type_class_dict:
core_portal_type_class_dict[portal_type_name]['generating'] = False
#LOG("ERP5Type.dynamic", INFO, #LOG("ERP5Type.dynamic", INFO,
# "Portal type %s loaded with bases %s" \ # "Portal type %s loaded with bases %s" \
# % (portal_type_name, repr(baseclasses))) # % (portal_type_name, repr(baseclasses)))
......
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