[Erp5-report] r15456 - /erp5/branches/products-CMFActivity-plone-integration/CMFActivity/
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Aug 3 15:08:23 CEST 2007
Author: tbenita
Date: Fri Aug 3 15:08:23 2007
New Revision: 15456
URL: http://svn.erp5.org?rev=15456&view=rev
Log:
Thierry forgot theses two files :-)
Added:
erp5/branches/products-CMFActivity-plone-integration/CMFActivity/TransactionalVariable.py
erp5/branches/products-CMFActivity-plone-integration/CMFActivity/Utils.py
Added: erp5/branches/products-CMFActivity-plone-integration/CMFActivity/TransactionalVariable.py
URL: http://svn.erp5.org/erp5/branches/products-CMFActivity-plone-integration/CMFActivity/TransactionalVariable.py?rev=15456&view=auto
==============================================================================
--- erp5/branches/products-CMFActivity-plone-integration/CMFActivity/TransactionalVariable.py (added)
+++ erp5/branches/products-CMFActivity-plone-integration/CMFActivity/TransactionalVariable.py Fri Aug 3 15:08:23 2007
@@ -1,0 +1,96 @@
+##############################################################################
+#
+# Copyright (c) 2007 Nexedi SA and Contributors. All Rights Reserved.
+# Yoshinori Okuji <yo at nexedi.com>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability 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
+# garantees 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
+#
+##############################################################################
+
+r"""This module provides an interface for transactional variables.
+
+Transactional variables are data slots which can store arbitrary values
+during a transaction. Transactional variables are guaranteed to vanish
+when a transaction finishes or aborts, and specific to a single thread and
+a single transaction. They are never shared by different threads.
+
+Transactional variables are different from user-defined data in a REQUEST
+object, in the sense that one request may execute multiple transactions, but
+not vice versa. If data should persist beyond a transaction, but must not
+persist over a single request, you should use a REQUEST object instead of
+transactional variables.
+
+Also, transactional variables are different from volatile attributes,
+because transactional variables may not disappear within a transaction.
+
+The constraint is that each key must be hashable, so that it can be used
+as a key to a dictionary.
+
+Example::
+
+ from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
+ tv = getTransactionalVariable()
+ try:
+ toto = tv['toto']
+ except KeyError:
+ toto = tv['toto'] = getToto()
+"""
+
+from UserDict import IterableUserDict
+from Shared.DC.ZRDB.TM import TM
+from threading import local
+
+class TransactionalVariable(TM, IterableUserDict):
+ """TransactionalVariable provides a dict-like look-n-feel.
+ This class must not be used directly outside.
+ """
+ _finalize = None
+
+ def _begin(self, *ignored):
+ pass
+
+ def _finish(self, *ignored):
+ self.clear()
+
+ def _abort(self, *ignored):
+ self.clear()
+
+ def __hash__(self):
+ return hash(id(self))
+
+ def __setitem__(self, key, value):
+ IterableUserDict.__setitem__(self, key, value)
+ self._register()
+
+transactional_variable_pool = local()
+
+def getTransactionalVariable(context):
+ """Return a transactional variable."""
+ portal = context.portal_url.getPortalObject()
+ try:
+ instance = transactional_variable_pool.instance
+ if getattr(portal, '_v_erp5_transactional_variable', None) is not instance:
+ portal._v_erp5_transactional_variable = instance
+ return instance
+ except AttributeError:
+ transactional_variable_pool.instance = TransactionalVariable()
+ return getTransactionalVariable(context)
Added: erp5/branches/products-CMFActivity-plone-integration/CMFActivity/Utils.py
URL: http://svn.erp5.org/erp5/branches/products-CMFActivity-plone-integration/CMFActivity/Utils.py?rev=15456&view=auto
==============================================================================
--- erp5/branches/products-CMFActivity-plone-integration/CMFActivity/Utils.py (added)
+++ erp5/branches/products-CMFActivity-plone-integration/CMFActivity/Utils.py Fri Aug 3 15:08:23 2007
@@ -1,0 +1,122 @@
+from Products.CMFCore import utils
+from zLOG import LOG, BLATHER
+
+def updateGlobals(*args, **kw):
+ pass
+
+def initializeProduct( context,
+ this_module,
+ global_hook,
+ document_module=None,
+ document_classes=None,
+ object_classes=None,
+ portal_tools=None,
+ content_constructors=None,
+ content_classes=None):
+ """
+ This function does all the initialization steps required
+ for a Zope / CMF Product
+ """
+ if document_classes is None: document_classes = []
+ if object_classes is None: object_classes = []
+ if portal_tools is None: portal_tools = []
+ if content_constructors is None: content_constructors = []
+ if content_classes is None: content_classes = []
+ product_name = this_module.__name__.split('.')[-1]
+
+ # Define content constructors for Document content classes (RAD)
+ extra_content_constructors = []
+ for content_class in content_classes:
+ if hasattr(content_class, 'add' + content_class.__name__):
+ extra_content_constructors += [
+ getattr(content_class, 'add' + content_class.__name__)]
+
+ # Define FactoryTypeInformations for all content classes
+ contentFactoryTypeInformations = []
+ for content in content_classes:
+ if hasattr(content, 'factory_type_information'):
+ contentFactoryTypeInformations.append(content.factory_type_information)
+
+ # Aggregate
+ content_constructors = list(content_constructors) + list(extra_content_constructors)
+
+ # Begin the initialization steps
+ bases = tuple(content_classes)
+ tools = portal_tools
+ z_bases = utils.initializeBasesPhase1( bases, this_module )
+ z_tool_bases = utils.initializeBasesPhase1( tools, this_module )
+
+ # Try to make some standard directories available
+ try:
+ registerDirectory('skins', global_hook)
+ except:
+ LOG("ERP5Type", BLATHER, "No skins directory for %s" % product_name)
+ try:
+ registerDirectory('help', global_hook)
+ except:
+ LOG("ERP5Type", BLATHER, "No help directory for %s" % product_name)
+
+ # Finish the initialization
+ utils.initializeBasesPhase2( z_bases, context )
+ utils.initializeBasesPhase2( z_tool_bases, context )
+
+ if len(tools) > 0:
+ try:
+ utils.ToolInit('%s Tool' % product_name,
+ tools=tools,
+ icon='tool.png',
+ ).initialize( context )
+ except TypeError:
+ # product_name parameter is deprecated in CMF
+ utils.ToolInit('%s Tool' % product_name,
+ tools=tools,
+ product_name=product_name,
+ icon='tool.png',
+ ).initialize( context )
+
+ for klass in content_classes:
+ # This id the default add permission to all ojects
+ klass_permission='Add portal content'
+ # We are looking if a permission type is defined in the document
+ if hasattr(klass, 'permission_type'):
+ klass_permission=klass.permission_type
+
+ #LOG("ContentInit", 0, str(content_constructors))
+ utils.ContentInit( klass.meta_type,
+ content_types=[klass],
+ permission=klass_permission,
+ extra_constructors=tuple(content_constructors),
+ fti=contentFactoryTypeInformations,
+ ).initialize( context )
+
+ # Register Help and API Reference
+ # This trick to make registerHelp work with 2 directories is taken from
+ # CMFCore
+ help = context.getProductHelp()
+ lastRegistered = help.lastRegistered
+ context.registerHelp(directory='help', clear=1)
+ context.registerHelp(directory='Interface', clear=1)
+ if help.lastRegistered != lastRegistered:
+ help.lastRegistered = None
+ context.registerHelp(directory='help', clear=1)
+ help.lastRegistered = None
+ context.registerHelp(directory='Interface', clear=0)
+
+ context.registerHelpTitle('%s Help' % product_name)
+
+ # Register Objets
+ for c in object_classes:
+ if hasattr(c, 'icon'):
+ icon = getattr(c, 'icon')
+ else:
+ icon = None
+ if hasattr(c, 'permission_type'):
+ context.registerClass( c,
+ constructors = c.constructors,
+ permission = c.permission_type,
+ icon = icon)
+ else:
+ context.registerClass( c,
+ constructors = c.constructors,
+ icon = icon)
+
More information about the Erp5-report
mailing list