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

updated for aq_dynamic code generation


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1317 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d3e6ed38
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
...@@ -30,16 +30,11 @@ ...@@ -30,16 +30,11 @@
and extended local roles management and extended local roles management
""" """
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals # Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import sys, Permissions
this_module = sys.modules[ __name__ ]
document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
# Finish installation # Finish installation
def initialize( context ): def initialize( context ):
......
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
from CategoryCore import CategoryCore
from BaseCategory import BaseCategory
\ No newline at end of file
...@@ -30,22 +30,11 @@ ...@@ -30,22 +30,11 @@
in the CMF. It is based on the ERP5Type RAD in the CMF. It is based on the ERP5Type RAD
""" """
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals # Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import Interface, PropertySheet, Permissions, Constraint import sys, Permissions
updateGlobals( this_module, globals(), this_module = sys.modules[ __name__ ]
property_sheet_module = PropertySheet, document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
interface_module = Interface,
permissions_module = Permissions,
constraint_module = Constraint)
# Define object classes and tools # Define object classes and tools
import Category, CategoryTool import Category, CategoryTool
......
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
...@@ -29,22 +29,11 @@ ...@@ -29,22 +29,11 @@
ERP5 Free Software ERP ERP5 Free Software ERP
""" """
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals # Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import Interface, PropertySheet, Permissions, Constraint import sys, Permissions
updateGlobals( this_module, globals(), this_module = sys.modules[ __name__ ]
property_sheet_module = PropertySheet, document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
interface_module = Interface,
permissions_module = Permissions,
constraint_module = Constraint)
# Define object classes and tools # Define object classes and tools
object_classes = () object_classes = ()
......
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
from Coordinate import Coordinate
from Entity import Entity
from Predicate import Predicate
from Variated import Variated
\ No newline at end of file
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
...@@ -29,25 +29,14 @@ ...@@ -29,25 +29,14 @@
ERP5 Free Software ERP ERP5 Free Software ERP
""" """
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals # Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import Interface, PropertySheet, Permissions, Constraint import sys, Permissions
updateGlobals( this_module, globals(), this_module = sys.modules[ __name__ ]
property_sheet_module = PropertySheet, document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
interface_module = Interface,
permissions_module = Permissions,
constraint_module = Constraint)
# Define object classes and tools # Define object classes and tools
from Tool import Category, CategoryTool, SimulationTool, RuleTool, IdTool, TemplateTool, TestTool from Tool import Category, CategoryTool, SimulationTool, RuleTool, IdTool, TemplateTool, TestTool, DomainTool
import ERP5Site import ERP5Site
object_classes = ( Category.Category, object_classes = ( Category.Category,
Category.BaseCategory, Category.BaseCategory,
...@@ -58,6 +47,7 @@ portal_tools = ( CategoryTool.CategoryTool, ...@@ -58,6 +47,7 @@ portal_tools = ( CategoryTool.CategoryTool,
RuleTool.RuleTool, RuleTool.RuleTool,
IdTool.IdTool, IdTool.IdTool,
TemplateTool.TemplateTool, TemplateTool.TemplateTool,
DomainTool.DomainTool,
TestTool.TestTool TestTool.TestTool
) )
content_classes = () content_classes = ()
...@@ -69,6 +59,8 @@ from InteractionWorkflow import InteractionWorkflowDefinition ...@@ -69,6 +59,8 @@ from InteractionWorkflow import InteractionWorkflowDefinition
# Finish installation # Finish installation
def initialize( context ): def initialize( context ):
import Document import Document
from zLOG import LOG
LOG('In ERP5 initialize', 0, '')
initializeProduct(context, this_module, globals(), initializeProduct(context, this_module, globals(),
document_module = Document, document_module = Document,
document_classes = document_classes, document_classes = document_classes,
......
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
...@@ -30,16 +30,11 @@ ...@@ -30,16 +30,11 @@
and extended local roles management and extended local roles management
""" """
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals # Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import sys, Permissions
this_module = sys.modules[ __name__ ]
document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
# Define object classes and tools # Define object classes and tools
import CatalogTool import CatalogTool
......
...@@ -3,6 +3,7 @@ import Products.ERP5 ...@@ -3,6 +3,7 @@ import Products.ERP5
import Products.ERP5.XML import Products.ERP5.XML
import Products.ERP5.UI import Products.ERP5.UI
import Products.ERP5.Document import Products.ERP5.Document
import Products.ERP5.Document.SaleOpportunity
import Products.ERP5Catalog import Products.ERP5Catalog
import Products.ERP5Form import Products.ERP5Form
import Products.ERP5SyncML import Products.ERP5SyncML
......
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
...@@ -30,19 +30,11 @@ ...@@ -30,19 +30,11 @@
with Zope with Zope
""" """
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals # Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import Permissions import sys, Permissions
updateGlobals( this_module, globals(), this_module = sys.modules[ __name__ ]
permissions_module = Permissions) document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
# Define object classes and tools # Define object classes and tools
import Form, FSForm, ListBox, MatrixBox, SelectionTool, ZGDChart, PDFTemplate import Form, FSForm, ListBox, MatrixBox, SelectionTool, ZGDChart, PDFTemplate
......
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
...@@ -29,22 +29,11 @@ ...@@ -29,22 +29,11 @@
ERP5Shop Free ERP + eCommerce ERP5Shop Free ERP + eCommerce
""" """
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals # Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import Interface, PropertySheet, Permissions, Constraint import sys, Permissions
updateGlobals( this_module, globals(), this_module = sys.modules[ __name__ ]
property_sheet_module = PropertySheet, document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
interface_module = Interface,
permissions_module = Permissions,
constraint_module = Constraint)
# Define object classes and tools # Define object classes and tools
import ShopManager import ShopManager
......
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
...@@ -30,24 +30,11 @@ ...@@ -30,24 +30,11 @@
and extended local roles management and extended local roles management
""" """
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals # Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import Interface, PropertySheet, Permissions, Constraint import sys, Permissions
updateGlobals( this_module, globals(), this_module = sys.modules[ __name__ ]
property_sheet_module = PropertySheet, document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
interface_module = Interface,
permissions_module = Permissions,
constraint_module = Constraint)
# Define object classes and tools # Define object classes and tools
import SynchronizationTool import SynchronizationTool
......
...@@ -65,8 +65,17 @@ import random ...@@ -65,8 +65,17 @@ import random
from zLOG import LOG from zLOG import LOG
class CallbaseError(AttributeError): # Dynamic method acquisition system (code generation)
pass aq_method_generated = {}
def _initializeDefaultProperties(klass):
if not aq_method_generated.has_key(klass):
LOG('in aq_method_generated %s' % id, 0, str(klass.__name__))
from Utils import initializeDefaultProperties
initializeDefaultProperties([klass])
aq_method_generated[klass] = 1
for super_klass in klass.__bases__:
_initializeDefaultProperties(super_klass)
class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyManager ): class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyManager ):
""" """
...@@ -114,6 +123,14 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana ...@@ -114,6 +123,14 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana
# We want to use a default property view # We want to use a default property view
manage_propertiesForm = DTMLFile( 'dtml/properties', _dtmldir ) manage_propertiesForm = DTMLFile( 'dtml/properties', _dtmldir )
def _aq_dynamic(self, id):
global aq_method_generated
klass = self.__class__
if not aq_method_generated.has_key(klass):
_initializeDefaultProperties(klass)
return getattr(self, id)
return None
# Constructor # Constructor
def __init__(self, id, uid=None, rid=None, sid=None, **kw): def __init__(self, id, uid=None, rid=None, sid=None, **kw):
self.id = id self.id = id
......
...@@ -38,9 +38,8 @@ product_document_registry = [] ...@@ -38,9 +38,8 @@ product_document_registry = []
def InitializeDocument(document_class, document_path=None): def InitializeDocument(document_class, document_path=None):
global product_document_registry global product_document_registry
InitializeClass(document_class)
# Register class in ERP5Type.Document # Register class in ERP5Type.Document
product_document_registry.append(((document_class.__name__, document_path))) product_document_registry.append(((document_class, document_path)))
#LOG('InitializeDocument', 0, document_class.__name__) #LOG('InitializeDocument', 0, document_class.__name__)
def initializeProductDocumentRegistry(): def initializeProductDocumentRegistry():
...@@ -51,163 +50,4 @@ def initializeProductDocumentRegistry(): ...@@ -51,163 +50,4 @@ def initializeProductDocumentRegistry():
#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, '')
#print 'Added product document to ERP5Type repository: %s (%s)' % (class_id, 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,
generate_document=1, generate_property_sheet=1, generate_constraint=1, generate_interface=1):
# Determine product_path
product_path = package_home( global_hook )
# Add _dtmldir
this_module._dtmldir = os.path.join( product_path, 'dtml' )
# This regular expression is used to check is a file is a python file
python_file_expr = re.compile("py$")
# Create Document __init__.py file
document_path = product_path + '/Document'
document_module_name_list = []
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:
if file_name != '__init__.py':
if python_file_expr.search(file_name,1):
module_name = file_name[0:-3]
document_module_name_list += [module_name]
document_module_lines += ["""\
# Hide internal implementation
from Products.ERP5Type.InitGenerator import InitializeDocument
import %s as ERP5%s
if not hasattr(ERP5TypeDocumentRepository, '_override_%s'): ERP5TypeDocumentRepository.%s = ERP5%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 = ERP5TypeDocumentRepository.%s.%s(id)
folder._setObject(id, o)
o.uid = folder.portal_catalog.newUid()
if kw is not None: o.__of__(folder)._edit(force_update=1, **kw)
# contentCreate already calls reindex 3 times ...
# o.reindexObject()
if REQUEST is not None:
REQUEST['RESPONSE'].redirect( 'manage_main' )
InitializeDocument(ERP5TypeDocumentRepository.%s.%s, document_path='%s')
class Temp%s(ERP5TypeDocumentRepository.%s.%s):
isIndexable = 0
def reindexObject(self, *args, **kw):
pass
def recursiveReindexObject(self, *args, **kw):
pass
def activate(self):
return self
def setUid(self, value):
self.uid = value # Make sure no casting happens when we use Temp classes to create new objects
from Products.PythonScripts.Utility import allow_class
allow_class(Temp%s)
def newTemp%s(folder, id, REQUEST=None, **kw):
o = Temp%s(id)
o = o.__of__(folder)
if kw is not None: o._edit(force_update=1, **kw)
return o
ERP5TypeDocumentRepository.newTemp%s = newTemp%s
from AccessControl import ModuleSecurityInfo
ModuleSecurityInfo('Products.ERP5Type.Document').declarePublic('newTemp%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, module_name, document_path,
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'))
document_init_file.close()
except:
LOG('ERP5Type:',0,'Could not write Document __init__.py files for %s' % product_path)
except:
LOG('ERP5Type:',0,'No Document directory in %s' % product_path)
# Create Property __init__.py file
property_path = product_path + '/PropertySheet'
property_module_name_list = []
property_module_lines = []
try:
file_list = os.listdir(property_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]
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'))
property_init_file.close()
except:
LOG('ERP5Type:',0,'Could not write PropertySheet __init__.py files for %s' % product_path)
except:
LOG('ERP5Type:',0,'No PropertySheet directory in %s' % product_path)
# Create Interface __init__.py file
interface_path = product_path + '/Interface'
interface_module_name_list = []
interface_module_lines = []
try:
file_list = os.listdir(interface_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]
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'))
interface_init_file.close()
except:
LOG('ERP5Type:',0,'Could not write Interface __init__.py files for %s' % product_path)
except:
LOG('ERP5Type:',0,'No Interface directory in %s' % product_path)
# Create Constraint __init__.py file
constraint_path = product_path + '/Constraint'
constraint_module_name_list = []
constraint_module_lines = []
try:
file_list = os.listdir(constraint_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]
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'))
constraint_init_file.close()
except:
LOG('ERP5Type:',0,'Could not write Constraint __init__.py files for %s' % product_path)
except:
LOG('ERP5Type:',0,'No Constraint directory in %s' % product_path)
return document_module_name_list
from Base import Base from Base import Base
from XMLObject import XMLObject
from SimpleItem import SimpleItem
from DublinCore import DublinCore from DublinCore import DublinCore
from Folder import Folder from Folder import Folder
\ No newline at end of file from SimpleItem import SimpleItem
from XMLObject import XMLObject
\ No newline at end of file
...@@ -40,12 +40,6 @@ from Products.ERP5Type import Constraint ...@@ -40,12 +40,6 @@ from Products.ERP5Type import Constraint
from Products.ERP5Type import Interface from Products.ERP5Type import Interface
from Products.ERP5Type import PropertySheet from Products.ERP5Type import PropertySheet
# This is really uggly... and we want to improve it
import Products.ERP5Type.Constraint.CategoryMembershipArity
import Products.ERP5Type.Constraint.AttributeEquality
import Products.ERP5Type.Constraint.PropertyTypeValidity
import Products.ERP5Type.Constraint.CategoryRelatedMembershipArity
from zLOG import LOG from zLOG import LOG
##################################################### #####################################################
...@@ -149,48 +143,68 @@ def getPath(o): ...@@ -149,48 +143,68 @@ def getPath(o):
# Globals initialization # Globals initialization
##################################################### #####################################################
from InitGenerator import InitializeDocument
# List Regexp
python_file_expr = re.compile("py$")
def getModuleIdList(product_path, module_id):
global python_file_expr
path = os.path.join(product_path, module_id)
module_name_list = []
module_lines = []
try:
file_list = os.listdir(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]
module_name_list += [module_name]
except:
LOG('ERP5Type:',0,'No PropertySheet directory in %s' % product_path)
return path, module_name_list
# EPR5Type global modules update # EPR5Type global modules update
def updateGlobals( this_module, global_hook, def updateGlobals( this_module, global_hook, permissions_module = None, is_erp5_type=0):
property_sheet_module = None,
interface_module = None,
permissions_module = None,
constraint_module = None):
""" """
This function does all the initialization steps required This function does all the initialization steps required
for a Zope / CMF Product for a Zope / CMF Product
""" """
product_name = this_module.__name__.split('.')[-1] product_path = package_home( global_hook )
# Update PropertySheet if not is_erp5_type:
if property_sheet_module is not None: # Add _dtmldir
for key in dir(property_sheet_module): this_module._dtmldir = os.path.join( product_path, 'dtml' )
# Do not consider private keys
if key[0:2] != '__': # Update PropertySheet Registry
setattr(PropertySheet, key, getattr(property_sheet_module, key)) for module_id in ('PropertySheet', 'Interface', 'Constraint', ):
path, module_id_list = getModuleIdList(product_path, module_id)
# Update Interface print path
if interface_module is not None: print module_id_list
for key in dir(interface_module): if module_id == 'PropertySheet':
# Do not consider private keys import_method = importLocalPropertySheet
if key[0:2] != '__': elif module_id == 'Interface':
setattr(Interface, key, getattr(interface_module, key)) import_method = importLocalInterface
elif module_id == 'Constraint':
# Update Permissions import_method = importLocalConstraint
if permissions_module is not None: else:
for key in dir(permissions_module): import_method = None
# Do not consider private keys for module_id in module_id_list:
if key[0:2] != '__': import_method(module_id, path=path)
setattr(Permissions, key, getattr(permissions_module, key))
# Update Permissions
# Update Constraint if permissions_module is not None:
if constraint_module is not None: for key in dir(permissions_module):
for key in dir(constraint_module): # Do not consider private keys
# Do not consider private keys if key[0:2] != '__':
if key[0:2] != '__': setattr(Permissions, key, getattr(permissions_module, key))
setattr(Constraint, key, getattr(constraint_module, key))
# Return document_class list
path, module_id_list = getModuleIdList(product_path, 'Document')
for document in module_id_list:
InitializeDocument(document, document_path=path)
return module_id_list
##################################################### #####################################################
# Modules Import # Modules Import
##################################################### #####################################################
...@@ -255,17 +269,36 @@ def writeLocalPropertySheet(class_id, text): ...@@ -255,17 +269,36 @@ def writeLocalPropertySheet(class_id, text):
f = open(path, 'w') f = open(path, 'w')
f.write(text) f.write(text)
def importLocalPropertySheet(class_id): def importLocalPropertySheet(class_id, path = None):
import Products.ERP5Type.PropertySheet import Products.ERP5Type.PropertySheet
import Permissions if path is None:
import Products instance_home = getConfiguration().instancehome
instance_home = getConfiguration().instancehome path = os.path.join(instance_home, "PropertySheet")
path = os.path.join(instance_home, "PropertySheet")
path = os.path.join(path, "%s.py" % class_id) path = os.path.join(path, "%s.py" % class_id)
f = open(path) f = open(path)
module = imp.load_source(class_id, path, f) module = imp.load_source(class_id, path, f)
setattr(Products.ERP5Type.PropertySheet, class_id, getattr(module, class_id)) setattr(Products.ERP5Type.PropertySheet, class_id, getattr(module, class_id))
def importLocalInterface(class_id, path = None):
import Products.ERP5Type.Interface
if path is None:
instance_home = getConfiguration().instancehome
path = os.path.join(instance_home, "Interface")
path = os.path.join(path, "%s.py" % class_id)
f = open(path)
module = imp.load_source(class_id, path, f)
setattr(Products.ERP5Type.Interface, class_id, getattr(module, class_id))
def importLocalConstraint(class_id, path = None):
import Products.ERP5Type.Interface
if path is None:
instance_home = getConfiguration().instancehome
path = os.path.join(instance_home, "Constraint")
path = os.path.join(path, "%s.py" % class_id)
f = open(path)
module = imp.load_source(class_id, path, f)
setattr(Products.ERP5Type.Constraint, class_id, getattr(module, class_id))
def getLocalExtensionList(): def getLocalExtensionList():
if not getConfiguration: return [] if not getConfiguration: return []
instance_home = getConfiguration().instancehome instance_home = getConfiguration().instancehome
...@@ -386,13 +419,12 @@ def importLocalDocument(class_id, document_path = None): ...@@ -386,13 +419,12 @@ def importLocalDocument(class_id, document_path = None):
document_constructor = DocumentConstructor(document_class) document_constructor = DocumentConstructor(document_class)
document_constructor_name = "add%s" % class_id document_constructor_name = "add%s" % class_id
document_constructor.__name__ = document_constructor_name document_constructor.__name__ = document_constructor_name
default_permission = ('Manager',) default_permission = ('Manager',)
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, class_id, document_module)
setattr(Products.ERP5Type.Document, document_constructor_name, document_constructor) setattr(Products.ERP5Type.Document, document_constructor_name, document_constructor)
setDefaultClassProperties(document_class) setDefaultClassProperties(document_class)
pr=PermissionRole(document_class.add_permission, default_permission) pr=PermissionRole(document_class.add_permission, default_permission)
initializeDefaultProperties([document_class]) document_constructor.__roles__ = pr # There used to be security breach which was fixed (None replaced by pr)
InitializeClass(document_class) InitializeClass(document_class)
# Update Meta Types # Update Meta Types
new_meta_types = [] new_meta_types = []
...@@ -454,7 +486,7 @@ def initializeLocalDocumentRegistry(): ...@@ -454,7 +486,7 @@ def initializeLocalDocumentRegistry():
LOG('Added local document to ERP5Type repository: %s (%s)' % (module_name, document_path),0,'') LOG('Added local document to ERP5Type repository: %s (%s)' % (module_name, document_path),0,'')
print 'Added local document to ERP5Type repository: %s (%s)' % (module_name, document_path) print 'Added local document to ERP5Type repository: %s (%s)' % (module_name, document_path)
except: except:
LOG('Failed to add local document to ERP5Type repository: %s (%s)' % (module_name, document_path) % (module_name, document_path),0,'') LOG('Failed to add local document to ERP5Type repository: %s (%s)' % (module_name, document_path),0,'')
print 'Failed to add local document to ERP5Type repository: %s (%s)' % (module_name, document_path) print 'Failed to add local document to ERP5Type repository: %s (%s)' % (module_name, document_path)
##################################################### #####################################################
...@@ -479,7 +511,8 @@ def initializeProduct( context, this_module, global_hook, ...@@ -479,7 +511,8 @@ def initializeProduct( context, this_module, global_hook,
# Define content classes from document_classes # Define content classes from document_classes
#LOG('Begin initializeProduct %s %s' % (document_module, document_classes),0,'') #LOG('Begin initializeProduct %s %s' % (document_module, document_classes),0,'')
extra_content_classes = [] extra_content_classes = []
if document_module is not None: #if document_module is not None:
if 0:
for module_name in document_classes: for module_name in document_classes:
#LOG('Inspecting %s %s' % (document_module, module_name),0,'') #LOG('Inspecting %s %s' % (document_module, module_name),0,'')
candidate = getattr(document_module, module_name) candidate = getattr(document_module, module_name)
...@@ -491,10 +524,11 @@ def initializeProduct( context, this_module, global_hook, ...@@ -491,10 +524,11 @@ def initializeProduct( context, this_module, global_hook,
# Initialize Default Properties and Constructors for RAD classes # Initialize Default Properties and Constructors for RAD classes
if INITIALIZE_PRODUCT_RAD: if INITIALIZE_PRODUCT_RAD:
initializeDefaultProperties(content_classes) #initializeDefaultProperties(content_classes)
initializeDefaultProperties(extra_content_classes) #initializeDefaultProperties(extra_content_classes)
initializeDefaultProperties(object_classes) initializeDefaultProperties(object_classes)
#initializeDefaultConstructors(content_classes) Does not work yet #initializeDefaultConstructors(content_classes) Does not work yet
# Define content constructors for Document content classes (RAD) # Define content constructors for Document content classes (RAD)
extra_content_constructors = [] extra_content_constructors = []
...@@ -667,7 +701,7 @@ def setDefaultProperties(klass): ...@@ -667,7 +701,7 @@ def setDefaultProperties(klass):
createCategoryAccessors(klass, cat) createCategoryAccessors(klass, cat)
createValueAccessors(klass, cat) createValueAccessors(klass, cat)
# Create the constraint method list - always check type # Create the constraint method list - always check type
klass.constraints = [Products.ERP5Type.Constraint.PropertyTypeValidity(id='type_check')] klass.constraints = [Constraint.PropertyTypeValidity(id='type_check')]
for const in constraint_list: for const in constraint_list:
createConstraintList(klass, constraint_definition=const) createConstraintList(klass, constraint_definition=const)
# ERP5 _properties and Zope _properties are somehow different # ERP5 _properties and Zope _properties are somehow different
......
...@@ -30,18 +30,14 @@ ...@@ -30,18 +30,14 @@
All ERP5 classes derive from ERP5Type All ERP5 classes derive from ERP5Type
""" """
# First import the minimal number of packages required by the code generation # Update ERP5 Globals
from Products.ERP5Type.InitGenerator import generateInitFiles import sys, Permissions, os
import sys from Globals import package_home
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ] this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals(), generate_document=0) product_path = package_home( globals() )
this_module._dtmldir = os.path.join( product_path, 'dtml' )
# Import rest of the code and finish installation from Products.ERP5Type.Utils import initializeProduct, updateGlobals
from Products.ERP5Type.Utils import initializeProduct, initializeLocalDocumentRegistry document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions, is_erp5_type = 1)
import Interface, PropertySheet, ZopePatch, StateChangeInfoPatch, \
CMFCorePatch
def initialize( context ): def initialize( context ):
# Import Product Components # Import Product Components
...@@ -60,10 +56,18 @@ def initialize( context ): ...@@ -60,10 +56,18 @@ def initialize( context ):
object_classes = object_classes, object_classes = object_classes,
portal_tools = portal_tools, portal_tools = portal_tools,
content_constructors = content_constructors, content_constructors = content_constructors,
content_classes = content_classes) content_classes = content_classes)
# We should register local classes at some point # # We should register interface classes at some point
# from Products.ERP5Type.InitGenerator import initializeProductInterfaceRegistry
# initializeProductInterfaceRegistry()
# # We should register property sheet classes at some point
# from Products.ERP5Type.InitGenerator import initializeProductPropertySheetRegistry
# initializeProductPropertySheetRegistry()
# We should register product classes at some point
from Products.ERP5Type.InitGenerator import initializeProductDocumentRegistry from Products.ERP5Type.InitGenerator import initializeProductDocumentRegistry
initializeProductDocumentRegistry() initializeProductDocumentRegistry()
# We should register local classes at some point
from Products.ERP5Type.Utils import initializeLocalDocumentRegistry
initializeLocalDocumentRegistry() initializeLocalDocumentRegistry()
from AccessControl.SecurityInfo import allow_module from AccessControl.SecurityInfo import allow_module
......
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
.AppleDouble .AppleDouble
*.pyc *.pyc
__init__.py
...@@ -29,22 +29,11 @@ ...@@ -29,22 +29,11 @@
ERP5 Free Software ERP ERP5 Free Software ERP
""" """
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals # Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import Interface, PropertySheet, Permissions, Constraint import sys, Permissions
updateGlobals( this_module, globals(), this_module = sys.modules[ __name__ ]
property_sheet_module = PropertySheet, document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
interface_module = Interface,
permissions_module = Permissions,
constraint_module = Constraint)
# Define object classes and tools # Define object classes and tools
object_classes = () object_classes = ()
......
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