[Erp5-report] r39785 jm - in /erp5/trunk/products/ERP5Type: InitGenerator.py Utils.py

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Nov 2 17:31:28 CET 2010


Author: jm
Date: Tue Nov  2 17:31:23 2010
New Revision: 39785

URL: http://svn.erp5.org?rev=39785&view=rev
Log:
Business Templates may redefine document classes

Modified:
    erp5/trunk/products/ERP5Type/InitGenerator.py
    erp5/trunk/products/ERP5Type/Utils.py

Modified: erp5/trunk/products/ERP5Type/InitGenerator.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/InitGenerator.py?rev=39785&r1=39784&r2=39785&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/InitGenerator.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/InitGenerator.py [utf8] Tue Nov  2 17:31:23 2010
@@ -64,7 +64,7 @@ def InitializeInteractor(interactor_clas
 def initializeProductDocumentRegistry():
   from Utils import importLocalDocument
   for (class_id, document_path) in product_document_registry:
-    importLocalDocument(class_id, document_path=document_path)
+    importLocalDocument(class_id, path=document_path)
     #from Testing import ZopeTestCase
     #ZopeTestCase._print('Added product document to ERP5Type repository: %s (%s) \n' % (class_id, document_path))
     #LOG('Added product document to ERP5Type repository: %s (%s)' % (class_id, document_path), 0, '')

Modified: erp5/trunk/products/ERP5Type/Utils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Utils.py?rev=39785&r1=39784&r2=39785&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Utils.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Utils.py [utf8] Tue Nov  2 17:31:23 2010
@@ -917,7 +917,7 @@ class PersistentMigrationMixin(object):
 
 from Globals import Persistent, PersistentMapping
 
-def importLocalDocument(class_id, document_path = None):
+def importLocalDocument(class_id, path=None):
   """Imports a document class and registers it in ERP5Type Document
   repository ( Products.ERP5Type.Document )
   """
@@ -925,17 +925,16 @@ def importLocalDocument(class_id, docume
   import Permissions
 
   from Products.ERP5Type import document_class_registry
-
-  classpath = document_class_registry.get(class_id)
-  if classpath is None:
-    # if the document was not registered before, it means that it is
-    # a local document in INSTANCE_HOME/Document/
+  if path and '/Products/' in path:
+    classpath = document_class_registry[class_id]
+    module_path = classpath.rsplit('.', 1)[0]
+    module = __import__(module_path, {}, {}, (module_path,))
+  else:
+    # local document in INSTANCE_HOME/Document/
     # (created by ClassTool?)
-    if document_path is None:
+    if path is None:
       instance_home = getConfiguration().instancehome
       path = os.path.join(instance_home, "Document")
-    else:
-      path = document_path
     path = os.path.join(path, "%s.py" % class_id)
     module_path = "erp5.document"
     classpath = "%s.%s" % (module_path, class_id)
@@ -943,9 +942,6 @@ def importLocalDocument(class_id, docume
     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]
-    module = __import__(module_path, {}, {}, (module_path,))
 
   ### Migration
   module_name = "Products.ERP5Type.Document.%s" % class_id
@@ -991,8 +987,7 @@ def importLocalDocument(class_id, docume
   return klass, tuple()
 
 
-def initializeLocalRegistry(directory_name, import_local_method,
-                            path_arg_name='path'):
+def initializeLocalRegistry(directory_name, import_local_method):
   """
   Initialize local directory.
   """
@@ -1010,8 +1005,7 @@ def initializeLocalRegistry(directory_na
       if python_file_expr.search(file_name,1):
         module_name = file_name[0:-3]
         try:
-          # XXX Arg are not consistent
-          import_local_method(module_name, **{path_arg_name: document_path})
+          import_local_method(module_name, path=document_path)
           LOG('ERP5Type', BLATHER,
               'Added local %s to ERP5Type repository: %s (%s)'
               % (directory_name, module_name, document_path))
@@ -1024,8 +1018,7 @@ def initializeLocalRegistry(directory_na
 
 def initializeLocalDocumentRegistry():
   # XXX Arg are not consistent
-  initializeLocalRegistry("Document", importLocalDocument,
-                          path_arg_name='document_path')
+  initializeLocalRegistry("Document", importLocalDocument)
 
 def initializeLocalPropertySheetRegistry():
   initializeLocalRegistry("PropertySheet", importLocalPropertySheet)




More information about the Erp5-report mailing list