diff --git a/product/ERP5Type/Utils.py b/product/ERP5Type/Utils.py index 93cf8a5ce878a6444e0596cef0eef5b5d9ed00b1..0071d5c1cf571cb1e87e9592511b4cac1464108f 100644 --- a/product/ERP5Type/Utils.py +++ b/product/ERP5Type/Utils.py @@ -1042,7 +1042,7 @@ def initializeProduct( context, try: import erp5.portal_type except ImportError: - from dynamic.portal_type_class import initializeDynamicModules + from dynamic.dynamic_module import initializeDynamicModules initializeDynamicModules() import erp5.portal_type diff --git a/product/ERP5Type/dynamic/dynamic_module.py b/product/ERP5Type/dynamic/dynamic_module.py index d292059204dceb8a14818bf271c72039e851ced2..2faea7325280abdfffa1ce126cabae2b0c971769 100644 --- a/product/ERP5Type/dynamic/dynamic_module.py +++ b/product/ERP5Type/dynamic/dynamic_module.py @@ -1,3 +1,32 @@ +############################################################################## +# +# Copyright (c) 2010-2012 Nexedi SARL and Contributors. All Rights Reserved. +# Nicolas Dumazet <nicolas.dumazet@nexedi.com> +# Arnaud Fontaine <arnaud.fontaine@nexedi.com> +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +############################################################################## + from types import ModuleType import sys import threading @@ -38,3 +67,52 @@ def registerDynamicModule(name, factory): d = DynamicModule(name, factory) sys.modules[name] = d return d + +def initializeDynamicModules(): + """ + Create erp5 module and its submodules + erp5.portal_type + holds portal type classes + erp5.temp_portal_type + holds portal type classes for temp objects + erp5.document + holds document classes that have no physical import path, + for example classes created through ClassTool that are in + $INSTANCE_HOME/Document + erp5.accessor_holder + holds accessor holders common to ZODB Property Sheets and Portal Types + erp5.accessor_holder.property_sheet + holds accessor holders of ZODB Property Sheets + erp5.accessor_holder.portal_type + holds accessors holders of Portal Types + """ + erp5 = ModuleType("erp5") + sys.modules["erp5"] = erp5 + + # Document classes without physical import path + erp5.document = ModuleType("erp5.document") + sys.modules["erp5.document"] = erp5.document + + # Portal types as classes + from accessor_holder import AccessorHolderType, AccessorHolderModuleType + + erp5.accessor_holder = AccessorHolderModuleType("erp5.accessor_holder") + sys.modules["erp5.accessor_holder"] = erp5.accessor_holder + + erp5.accessor_holder.property_sheet = \ + AccessorHolderModuleType("erp5.accessor_holder.property_sheet") + + sys.modules["erp5.accessor_holder.property_sheet"] = \ + erp5.accessor_holder.property_sheet + + erp5.accessor_holder.portal_type = registerDynamicModule( + 'erp5.accessor_holder.portal_type', + AccessorHolderModuleType) + + from lazy_class import generateLazyPortalTypeClass + erp5.portal_type = registerDynamicModule('erp5.portal_type', + generateLazyPortalTypeClass) + + from portal_type_class import loadTempPortalTypeClass + erp5.temp_portal_type = registerDynamicModule('erp5.temp_portal_type', + loadTempPortalTypeClass) diff --git a/product/ERP5Type/dynamic/portal_type_class.py b/product/ERP5Type/dynamic/portal_type_class.py index 658f73aaa7ca7877876cd70fac72558d75ba3c71..c165b4fff99de1b4121e9fafae70dffe49b07f3e 100644 --- a/product/ERP5Type/dynamic/portal_type_class.py +++ b/product/ERP5Type/dynamic/portal_type_class.py @@ -31,16 +31,13 @@ import sys import os import inspect import transaction -from types import ModuleType -from Products.ERP5Type.dynamic.dynamic_module import registerDynamicModule from Products.ERP5Type.mixin.temporary import TemporaryDocumentMixin from Products.ERP5Type.Base import Base, resetRegisteredWorkflowMethod from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.Utils import setDefaultClassProperties from Products.ERP5Type import document_class_registry, mixin_class_registry -from Products.ERP5Type.dynamic.accessor_holder import AccessorHolderModuleType, \ - createAllAccessorHolderList +from Products.ERP5Type.dynamic.accessor_holder import createAllAccessorHolderList from Products.ERP5Type.TransactionalVariable import TransactionalResource from zLOG import LOG, ERROR, INFO, WARNING, PANIC @@ -250,63 +247,20 @@ def generatePortalTypeClass(site, portal_type_name): interface_class_list, attribute_dict) -from lazy_class import generateLazyPortalTypeClass -def initializeDynamicModules(): +def loadTempPortalTypeClass(portal_type_name): """ - Create erp5 module and its submodules - erp5.portal_type - holds portal type classes - erp5.temp_portal_type - holds portal type classes for temp objects - erp5.document - holds document classes that have no physical import path, - for example classes created through ClassTool that are in - $INSTANCE_HOME/Document - erp5.accessor_holder - holds accessor holders common to ZODB Property Sheets and Portal Types - erp5.accessor_holder.property_sheet - holds accessor holders of ZODB Property Sheets - erp5.accessor_holder.portal_type - holds accessors holders of Portal Types - """ - erp5 = ModuleType("erp5") - sys.modules["erp5"] = erp5 - erp5.document = ModuleType("erp5.document") - sys.modules["erp5.document"] = erp5.document - erp5.accessor_holder = AccessorHolderModuleType("erp5.accessor_holder") - sys.modules["erp5.accessor_holder"] = erp5.accessor_holder - - erp5.accessor_holder.property_sheet = \ - AccessorHolderModuleType("erp5.accessor_holder.property_sheet") - - sys.modules["erp5.accessor_holder.property_sheet"] = \ - erp5.accessor_holder.property_sheet - - erp5.accessor_holder.portal_type = registerDynamicModule( - 'erp5.accessor_holder.portal_type', - AccessorHolderModuleType) - - portal_type_container = registerDynamicModule('erp5.portal_type', - generateLazyPortalTypeClass) + Returns a class suitable for a temporary portal type - erp5.portal_type = portal_type_container - - def loadTempPortalTypeClass(portal_type_name): - """ - Returns a class suitable for a temporary portal type - - This class will in fact be a subclass of erp5.portal_type.xxx, which - means that loading an attribute on this temporary portal type loads - the lazily-loaded parent class, and that any changes on the parent - class will be reflected on the temporary objects. - """ - klass = getattr(portal_type_container, portal_type_name) - - return type("Temporary %s" % portal_type_name, - (TemporaryDocumentMixin, klass), {}) + This class will in fact be a subclass of erp5.portal_type.xxx, which + means that loading an attribute on this temporary portal type loads + the lazily-loaded parent class, and that any changes on the parent + class will be reflected on the temporary objects. + """ + import erp5.portal_type + klass = getattr(erp5.portal_type, portal_type_name) - erp5.temp_portal_type = registerDynamicModule('erp5.temp_portal_type', - loadTempPortalTypeClass) + return type("Temporary %s" % portal_type_name, + (TemporaryDocumentMixin, klass), {}) last_sync = -1 _bootstrapped = set()