Commit 4d3dce60 authored by Yoshinori Okuji's avatar Yoshinori Okuji

More simplification and safer exception catching.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39465 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 67a9595d
...@@ -100,59 +100,33 @@ def generatePortalTypeClass(portal_type_name): ...@@ -100,59 +100,33 @@ def generatePortalTypeClass(portal_type_name):
and computes __bases__ and __dict__ for the class that will and computes __bases__ and __dict__ for the class that will
be created to represent this portal type be created to represent this portal type
""" """
#LOG("ERP5Type.dynamic", 0, "Loading portal type %s..." % portal_type_name) from Products.ERP5.ERP5Site import getSite
site = getSite()
types_tool = site.portal_types
portal_type = None
mixin_list = [] mixin_list = []
interface_list = [] interface_list = []
accessor_holder_list = [] accessor_holder_list = []
from Products.ERP5.ERP5Site import getSite
site = getSite()
types_tool = site.portal_types
try: try:
portal_type = getattr(types_tool, portal_type_name) portal_type = types_tool[portal_type_name]
except KeyError:
# Try to figure out a coresponding document class from the document side.
# This can happen when calling newTempAmount for instance:
# Amount has no corresponding Base Type and will never have one
# But the semantic of newTempXXX requires us to create an
# object using the Amount Document, so we promptly do it:
type_class = portal_type_name.replace(' ', '')
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) # was not migrated yet)
type_class = portal_type.getTypeClass() type_class = portal_type.getTypeClass()
# But no such getter exists for Mixins and Interfaces:
# in reality, we can live with such a failure
try:
mixin_list = portal_type.getTypeMixinList() mixin_list = portal_type.getTypeMixinList()
interface_list = portal_type.getTypeInterfaceList() 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 can happen when calling newTempAmount for instance:
# Amount has no corresponding Base Type and will never have one
# But the semantic of newTempXXX requires us to create an
# object using the Amount Document, so we promptly do it:
for name, path in document_class_registry.iteritems():
module_path, class_name = path.rsplit('.', 1)
if portal_type_name.replace(' ', '') != class_name:
continue
module = __import__(module_path, {}, {}, (module_path,))
try:
klass = getattr(module, class_name)
try:
document_portal_type = getattr(klass, 'portal_type')
if document_portal_type == portal_type_name:
type_class = name
break
except AttributeError:
pass
finally:
del klass
type_class_path = None
if type_class is not None:
type_class_path = document_class_registry.get(type_class) type_class_path = document_class_registry.get(type_class)
if type_class_path is None: if type_class_path is None:
raise AttributeError('Document class is not defined on Portal Type %s' \ raise AttributeError('Document class is not defined on Portal Type %s' \
......
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