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

Added parameters not to modify __init__.py


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@233 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0f0c1bfd
......@@ -29,12 +29,20 @@
import os, re, string, sys
from Globals import package_home
from Globals import package_home, InitializeClass
from zLOG import LOG
def InitializeDocument(document_class):
InitializeClass(document_class)
# We should instead create a subclass
# attach it to a temp module in ERP5Type.Document
# and register it
# Code Generation of __init__.py files
def generateInitFiles(this_module, global_hook):
def generateInitFiles(this_module, global_hook,
generate_document=1, generate_property_sheet=1, generate_constraint=1, generate_interface=1):
# Determine product_path
product_path = package_home( global_hook )
# Add _dtmldir
......@@ -45,7 +53,7 @@ def generateInitFiles(this_module, global_hook):
# Create Document __init__.py file
document_path = product_path + '/Document'
document_module_name_list = []
document_module_lines = []
document_module_lines = ["from Products.ERP5Type import Document as ERP5TypeDocumentRepository\n\n"]
try:
file_list = os.listdir(document_path)
for file_name in file_list:
......@@ -55,12 +63,13 @@ def generateInitFiles(this_module, global_hook):
document_module_name_list += [module_name]
document_module_lines += ["""\
# Hide internal implementation
from Globals import InitializeClass
from %s import %s as ERP5%s
from Products.ERP5Type.InitGenerator import InitializeDocument
import %s as ERP5%s
if not hasattr(ERP5TypeDocumentRepository, '_override_%s'): ERP5TypeDocumentRepository.%s = ERP5%s.%s # Never override a local Document class
# Default constructor for %s
# Can be overriden by adding a method add%s in class %s
def add%s(folder, id, REQUEST=None, **kw):
o = ERP5%s(id)
o = ERP5TypeDocumentRepository.%s(id)
folder._setObject(id, o)
if kw is not None: o.__of__(folder)._edit(force_update=1, **kw)
# contentCreate already calls reindex 3 times ...
......@@ -68,9 +77,16 @@ def add%s(folder, id, REQUEST=None, **kw):
if REQUEST is not None:
REQUEST['RESPONSE'].redirect( 'manage_main' )
InitializeClass(ERP5%s)
""" % (module_name, module_name, module_name, module_name, module_name, module_name, module_name, module_name, module_name)]
InitializeDocument(ERP5TypeDocumentRepository.%s)
""" % (module_name, module_name,
module_name, module_name, module_name, module_name,
module_name,
module_name, module_name,
module_name,
module_name,
module_name,)]
if generate_document:
try:
document_init_file = open(document_path + '/__init__.py', 'w')
document_init_file.write(string.join(document_module_lines, '\n'))
......@@ -92,6 +108,7 @@ InitializeClass(ERP5%s)
module_name = file_name[0:-3]
property_module_name_list += [module_name]
property_module_lines += ['from %s import %s' % (module_name, module_name)]
if generate_property_sheet:
try:
property_init_file = open(property_path + '/__init__.py', 'w')
property_init_file.write(string.join(property_module_lines, '\n'))
......@@ -113,6 +130,7 @@ InitializeClass(ERP5%s)
module_name = file_name[0:-3]
interface_module_name_list += [module_name]
interface_module_lines += ['from %s import %s' % (module_name, module_name)]
if generate_interface:
try:
interface_init_file = open(interface_path + '/__init__.py', 'w')
interface_init_file.write(string.join(interface_module_lines, '\n'))
......@@ -134,6 +152,7 @@ InitializeClass(ERP5%s)
module_name = file_name[0:-3]
constraint_module_name_list += [module_name]
constraint_module_lines += ['from %s import %s' % (module_name, module_name)]
if generate_constraint:
try:
constraint_init_file = open(constraint_path + '/__init__.py', 'w')
constraint_init_file.write(string.join(constraint_module_lines, '\n'))
......
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