Commit f33642c5 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Loads product documents and class documents


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@465 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c38ce54b
......@@ -33,12 +33,20 @@ from Globals import package_home, InitializeClass
from zLOG import LOG
def InitializeDocument(document_class):
global product_document_registry
product_document_registry = []
def InitializeDocument(document_class, document_path=None):
global product_document_registry
InitializeClass(document_class)
# We should instead create a subclass
# attach it to a temp module in ERP5Type.Document
# and register it
# Register class in ERP5Type.Document
product_document_registry.append(((document_class.__name__, document_path)))
def initializeProductDocumentRegistry():
from Utils import importLocalDocument
for (class_id, document_path) in product_document_registry:
importLocalDocument(class_id, document_path=document_path)
print 'Added product document to ERP5Type repository: %s (%s)' % (class_id, document_path)
# Code Generation of __init__.py files
def generateInitFiles(this_module, global_hook,
......@@ -77,7 +85,7 @@ def add%s(folder, id, REQUEST=None, **kw):
if REQUEST is not None:
REQUEST['RESPONSE'].redirect( 'manage_main' )
InitializeDocument(ERP5TypeDocumentRepository.%s)
InitializeDocument(ERP5TypeDocumentRepository.%s, document_path='%s')
class Temp%s(ERP5TypeDocumentRepository.%s):
isIndexable = 0
......@@ -110,7 +118,7 @@ ModuleSecurityInfo('Products.ERP5Type.Document').declarePublic('newTemp%s',)
module_name, module_name,
module_name,
module_name,
module_name,
module_name, document_path,
module_name, module_name,
module_name,
module_name,
......
......@@ -48,6 +48,12 @@ import Products.ERP5Type.Constraint.CategoryRelatedMembershipArity
from zLOG import LOG
#####################################################
# Global Switches
#####################################################
INITIALIZE_PRODUCT_RAD = 1 # If set to 0, product documents are not initialized
#####################################################
# Compatibility - XXX - BAD
#####################################################
......@@ -308,7 +314,7 @@ def writeLocalDocument(class_id, text):
f = open(path, 'w')
f.write(text)
def importLocalDocument(class_id):
def importLocalDocument(class_id, document_path = None):
"""
Imports a document class and registers it as
"""
......@@ -317,8 +323,11 @@ def importLocalDocument(class_id):
import Products.ERP5Type.Document
import Permissions
import Products
if document_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)
f = open(path)
document_module = imp.load_source('Products.ERP5Type.Document.%s' % class_id, path, f) # This is the right way
......@@ -327,7 +336,6 @@ def importLocalDocument(class_id):
document_constructor_name = "add%s" % class_id
document_constructor.__name__ = document_constructor_name
default_permission = ('Manager',)
pr=PermissionRole(document_class.add_permission, default_permission)
document_constructor.__roles__=None # XXX This is a security breach which needs to be fixed
setattr(Products.ERP5Type.Document, class_id, document_module)
setattr(Products.ERP5Type.Document, document_constructor_name, document_constructor)
......@@ -339,6 +347,9 @@ def importLocalDocument(class_id):
document_class.add_permission = Permissions.AddPortalContent
if not hasattr(document_class, '__implements__'):
document_class.__implements__ = ()
if not hasattr(document_class, 'property_sheets'):
document_class.property_sheets = ()
pr=PermissionRole(document_class.add_permission, default_permission)
initializeDefaultProperties([document_class])
InitializeClass(document_class)
# Update Meta Types
......@@ -358,7 +369,7 @@ def importLocalDocument(class_id):
'instance': instance_class,
'container_filter': None
},)
Products.meta_types = new_meta_types
Products.meta_types = tuple(new_meta_types)
# Update Constructors
m = Products.ERP5Type._m
constructors = ( manage_addContentForm
......@@ -381,6 +392,20 @@ def importLocalDocument(class_id):
# except IOError,
def initializeLocalDocumentRegistry():
instance_home = getConfiguration().instancehome
document_path = os.path.join(instance_home, "Document")
python_file_expr = re.compile("py$")
file_list = os.listdir(document_path)
for file_name in file_list:
if file_name != '__init__.py':
if python_file_expr.search(file_name,1):
module_name = file_name[0:-3]
try:
importLocalDocument(module_name, document_path = document_path)
print 'Added local document to ERP5Type repository: %s (%s)' % (module_name, document_path)
except:
print 'Failed to add local document to ERP5Type repository: %s (%s)' % (module_name, document_path)
#####################################################
# Product initialization
......@@ -410,6 +435,7 @@ def initializeProduct( context, this_module, global_hook,
extra_content_classes += [candidate]
# Initialize Default Properties and Constructors for RAD classes
if INITIALIZE_PRODUCT_RAD:
initializeDefaultProperties(content_classes)
initializeDefaultProperties(extra_content_classes)
initializeDefaultProperties(object_classes)
......
......@@ -39,7 +39,7 @@ this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals(), generate_document=0)
# Import rest of the code and finish installation
from Products.ERP5Type.Utils import initializeProduct
from Products.ERP5Type.Utils import initializeProduct, initializeLocalDocumentRegistry
import Interface, PropertySheet, ZopePatch, StateChangeInfoPatch, \
CMFCorePatch
......@@ -61,3 +61,7 @@ def initialize( context ):
portal_tools = portal_tools,
content_constructors = content_constructors,
content_classes = content_classes)
# We should register local classes at some point
from Products.ERP5Type.InitGenerator import initializeProductDocumentRegistry
initializeProductDocumentRegistry()
initializeLocalDocumentRegistry()
\ No newline at end of file
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