[Erp5-report] r39465 yo - /erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Oct 22 09:58:41 CEST 2010
Author: yo
Date: Fri Oct 22 09:58:41 2010
New Revision: 39465
URL: http://svn.erp5.org?rev=39465&view=rev
Log:
More simplification and safer exception catching.
Modified:
erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py
Modified: erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py?rev=39465&r1=39464&r2=39465&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py [utf8] Fri Oct 22 09:58:41 2010
@@ -100,60 +100,34 @@ def generatePortalTypeClass(portal_type_
and computes __bases__ and __dict__ for the class that will
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 = []
interface_list = []
accessor_holder_list = []
- from Products.ERP5.ERP5Site import getSite
- site = getSite()
-
- types_tool = site.portal_types
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
# something even if the field is not set (i.e. Base Type object
# was not migrated yet)
type_class = portal_type.getTypeClass()
+ mixin_list = portal_type.getTypeMixinList()
+ interface_list = portal_type.getTypeInterfaceList()
- # But no such getter exists for Mixins and Interfaces:
- # in reality, we can live with such a failure
- 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 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:
raise AttributeError('Document class is not defined on Portal Type %s' \
% portal_type_name)
More information about the Erp5-report
mailing list