Commit a4b8c5f3 authored by Julien Muchembled's avatar Julien Muchembled

Business Templates may redefine document classes

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39785 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 56f68692
...@@ -64,7 +64,7 @@ def InitializeInteractor(interactor_class, interactor_path=None): ...@@ -64,7 +64,7 @@ def InitializeInteractor(interactor_class, interactor_path=None):
def initializeProductDocumentRegistry(): def initializeProductDocumentRegistry():
from Utils import importLocalDocument from Utils import importLocalDocument
for (class_id, document_path) in product_document_registry: 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 #from Testing import ZopeTestCase
#ZopeTestCase._print('Added product document to ERP5Type repository: %s (%s) \n' % (class_id, document_path)) #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, '') #LOG('Added product document to ERP5Type repository: %s (%s)' % (class_id, document_path), 0, '')
......
...@@ -917,7 +917,7 @@ class PersistentMigrationMixin(object): ...@@ -917,7 +917,7 @@ class PersistentMigrationMixin(object):
from Globals import Persistent, PersistentMapping 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 """Imports a document class and registers it in ERP5Type Document
repository ( Products.ERP5Type.Document ) repository ( Products.ERP5Type.Document )
""" """
...@@ -925,17 +925,16 @@ def importLocalDocument(class_id, document_path = None): ...@@ -925,17 +925,16 @@ def importLocalDocument(class_id, document_path = None):
import Permissions import Permissions
from Products.ERP5Type import document_class_registry from Products.ERP5Type import document_class_registry
if path and '/Products/' in path:
classpath = document_class_registry.get(class_id) classpath = document_class_registry[class_id]
if classpath is None: module_path = classpath.rsplit('.', 1)[0]
# if the document was not registered before, it means that it is module = __import__(module_path, {}, {}, (module_path,))
# a local document in INSTANCE_HOME/Document/ else:
# local document in INSTANCE_HOME/Document/
# (created by ClassTool?) # (created by ClassTool?)
if document_path is None: if path is None:
instance_home = getConfiguration().instancehome instance_home = getConfiguration().instancehome
path = os.path.join(instance_home, "Document") path = os.path.join(instance_home, "Document")
else:
path = document_path
path = os.path.join(path, "%s.py" % class_id) path = os.path.join(path, "%s.py" % class_id)
module_path = "erp5.document" module_path = "erp5.document"
classpath = "%s.%s" % (module_path, class_id) classpath = "%s.%s" % (module_path, class_id)
...@@ -943,9 +942,6 @@ def importLocalDocument(class_id, document_path = None): ...@@ -943,9 +942,6 @@ def importLocalDocument(class_id, document_path = None):
import erp5.document import erp5.document
setattr(erp5.document, class_id, getattr(module, class_id)) setattr(erp5.document, class_id, getattr(module, class_id))
document_class_registry[class_id] = classpath document_class_registry[class_id] = classpath
else:
module_path = classpath.rsplit('.', 1)[0]
module = __import__(module_path, {}, {}, (module_path,))
### Migration ### Migration
module_name = "Products.ERP5Type.Document.%s" % class_id module_name = "Products.ERP5Type.Document.%s" % class_id
...@@ -991,8 +987,7 @@ def importLocalDocument(class_id, document_path = None): ...@@ -991,8 +987,7 @@ def importLocalDocument(class_id, document_path = None):
return klass, tuple() return klass, tuple()
def initializeLocalRegistry(directory_name, import_local_method, def initializeLocalRegistry(directory_name, import_local_method):
path_arg_name='path'):
""" """
Initialize local directory. Initialize local directory.
""" """
...@@ -1010,8 +1005,7 @@ def initializeLocalRegistry(directory_name, import_local_method, ...@@ -1010,8 +1005,7 @@ def initializeLocalRegistry(directory_name, import_local_method,
if python_file_expr.search(file_name,1): if python_file_expr.search(file_name,1):
module_name = file_name[0:-3] module_name = file_name[0:-3]
try: try:
# XXX Arg are not consistent import_local_method(module_name, path=document_path)
import_local_method(module_name, **{path_arg_name: document_path})
LOG('ERP5Type', BLATHER, LOG('ERP5Type', BLATHER,
'Added local %s to ERP5Type repository: %s (%s)' 'Added local %s to ERP5Type repository: %s (%s)'
% (directory_name, module_name, document_path)) % (directory_name, module_name, document_path))
...@@ -1024,8 +1018,7 @@ def initializeLocalRegistry(directory_name, import_local_method, ...@@ -1024,8 +1018,7 @@ def initializeLocalRegistry(directory_name, import_local_method,
def initializeLocalDocumentRegistry(): def initializeLocalDocumentRegistry():
# XXX Arg are not consistent # XXX Arg are not consistent
initializeLocalRegistry("Document", importLocalDocument, initializeLocalRegistry("Document", importLocalDocument)
path_arg_name='document_path')
def initializeLocalPropertySheetRegistry(): def initializeLocalPropertySheetRegistry():
initializeLocalRegistry("PropertySheet", importLocalPropertySheet) initializeLocalRegistry("PropertySheet", importLocalPropertySheet)
......
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