Commit 1c7f2108 authored by Nicolas Dumazet's avatar Nicolas Dumazet

Partly re-add hardcoding for bootstraping.

you can't call getattr(type_tool, portal_type_name) if Base Type
and Solver Type portal types are not loaded yet:
  type_tool[portal_type_name].__of__(type_tool)
requires loading the class to access __of__ method.

For now, we'll have to hardcode a bit more to get test results.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39415 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b7e3f136
...@@ -111,49 +111,54 @@ def portalTypeFactory(portal_type_name): ...@@ -111,49 +111,54 @@ def portalTypeFactory(portal_type_name):
site = getSite() site = getSite()
type_tool = site.portal_types type_tool = site.portal_types
try: if portal_type_name == "Base Type":
portal_type = getattr(type_tool, portal_type_name) type_class = "ERP5TypeInformation"
except: elif portal_type_name == "Solver Type":
raise AttributeError('portal type %s not found in Types Tool' \ type_class = "SolverTypeInformation"
% portal_type_name) else:
# type_class has a compatibility getter that should return
# something even if the field is not set (i.e. Base Type object
# was not migrated yet)
try:
type_class = portal_type.getTypeClass()
# But no such getter exists for Mixins and Interfaces:
# in reality, we can live with such a failure
try: try:
mixin_list = portal_type.getTypeMixinList() portal_type = getattr(type_tool, portal_type_name)
interface_list = portal_type.getTypeInterfaceList() except:
except StandardError: raise AttributeError('portal type %s not found in Types Tool' \
# log loudly the error, but it's not _critical_ % portal_type_name)
LOG("ERP5Type.Dynamic", ERROR,
"Could not load interfaces or Mixins for portal type %s" \ # type_class has a compatibility getter that should return
% portal_type_name) # something even if the field is not set (i.e. Base Type object
except AttributeError: # was not migrated yet)
# Try to figure out a coresponding document class from the document side. try:
# This is required for the bootstrap (e.g. Base Type). type_class = portal_type.getTypeClass()
for name, path in document_class_registry.iteritems():
# XXX heuristic: bootstrap issues should happen only inside ERP5Type. # But no such getter exists for Mixins and Interfaces:
if not path.startswith('Products.ERP5Type.'): # in reality, we can live with such a failure
continue
module_path, class_name = path.rsplit('.', 1)
module = __import__(module_path, {}, {}, (module_path,))
klass = getattr(module, class_name)
try: try:
mixin_list = portal_type.getTypeMixinList()
interface_list = portal_type.getTypeInterfaceList()
except StandardError:
# log loudly the error, but it's not _critical_
LOG("ERP5Type.Dynamic", ERROR,
"Could not load interfaces or Mixins for portal type %s" \
% portal_type_name)
except AttributeError:
# Try to figure out a coresponding document class from the document side.
# This is required for the bootstrap (e.g. Base Category).
for name, path in document_class_registry.iteritems():
# XXX heuristic: bootstrap issues should happen only inside ERP5Type.
if not path.startswith('Products.ERP5Type.'):
continue
module_path, class_name = path.rsplit('.', 1)
module = __import__(module_path, {}, {}, (module_path,))
klass = getattr(module, class_name)
try: try:
document_portal_type = getattr(klass, 'portal_type') try:
if document_portal_type == portal_type_name: document_portal_type = getattr(klass, 'portal_type')
type_class = name if document_portal_type == portal_type_name:
break type_class = name
except AttributeError: break
pass except AttributeError:
finally: pass
del klass finally:
del klass
if type_class is not None: if type_class is not None:
type_class = document_class_registry.get(type_class) type_class = document_class_registry.get(type_class)
......
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