[Erp5-report] r39418 nicolas.dumazet - /erp5/trunk/products/ERP5Type/Utils.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Oct 21 08:21:38 CEST 2010
Author: nicolas.dumazet
Date: Thu Oct 21 08:21:38 2010
New Revision: 39418
URL: http://svn.erp5.org?rev=39418&view=rev
Log:
fix behavior of portal_classes when writing a new Document
and when re-importing an existing document.
In both cases, the generated class is stored in erp5.document.xxx
and we should explicitely setattr() on erp5.document
Modified:
erp5/trunk/products/ERP5Type/Utils.py
Modified: erp5/trunk/products/ERP5Type/Utils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Utils.py?rev=39418&r1=39417&r2=39418&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Utils.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Utils.py [utf8] Thu Oct 21 08:21:38 2010
@@ -831,13 +831,16 @@ def writeLocalDocument(class_id, text, c
f.write(text)
finally:
f.close()
- # load the file, so that an error is raised if file is invalid
- module = imp.load_source(class_id, path)
- getattr(module, class_id)
+
+ module_path = "erp5.document"
+ classpath = "%s.%s" % (module_path, class_id)
+ module = imp.load_source(classpath, path)
+ import erp5.document
+ setattr(erp5.document, class_id, getattr(module, class_id))
# and register correctly the new document
from Products.ERP5Type import document_class_registry
- document_class_registry[class_id] = "%s.%s" % (module.__name__, class_id)
+ document_class_registry[class_id] = classpath
def setDefaultClassProperties(property_holder):
"""Initialize default properties for ERP5Type Documents.
@@ -935,10 +938,9 @@ def importLocalDocument(class_id, docume
path = os.path.join(path, "%s.py" % class_id)
module_path = "erp5.document"
classpath = "%s.%s" % (module_path, class_id)
- try:
- module = imp.load_source(classpath, path)
- except:
- raise AttributeError("document was not registered: %s, %s" % (class_id, document_path))
+ module = imp.load_source(classpath, path)
+ import erp5.document
+ setattr(erp5.document, class_id, getattr(module, class_id))
document_class_registry[class_id] = classpath
else:
module_path = classpath.rsplit('.', 1)[0]
More information about the Erp5-report
mailing list