Commit b016df0f authored by Nicolas Dumazet's avatar Nicolas Dumazet

use document_registry to determine Document paths

when no Base Type is defined in TypesTool.

This should ensure that newTempXXX calls succeed, without needing abstract Base
Type objects, *if* the Document correctly defines portal_type attribute on the
Document class.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39461 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5860dea3
...@@ -112,9 +112,6 @@ def generatePortalTypeClass(portal_type_name): ...@@ -112,9 +112,6 @@ def generatePortalTypeClass(portal_type_name):
types_tool = site.portal_types types_tool = site.portal_types
try: try:
portal_type = getattr(types_tool, portal_type_name) portal_type = getattr(types_tool, portal_type_name)
except AttributeError:
raise AttributeError('portal type %s not found in Types Tool' \
% portal_type_name)
# 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
...@@ -131,6 +128,28 @@ def generatePortalTypeClass(portal_type_name): ...@@ -131,6 +128,28 @@ def generatePortalTypeClass(portal_type_name):
LOG("ERP5Type.dynamic", ERROR, LOG("ERP5Type.dynamic", ERROR,
"Could not load interfaces or Mixins for portal type %s" \ "Could not load interfaces or Mixins for portal type %s" \
% portal_type_name) % 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 type_class_path = None
if type_class is not None: if type_class is not None:
......
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