[Erp5-report] r13817 - in /erp5/trunk/products/ERP5Type: ./ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Mar 30 12:02:47 CEST 2007
Author: yo
Date: Fri Mar 30 12:02:36 2007
New Revision: 13817
URL: http://svn.erp5.org?rev=13817&view=rev
Log:
Pass context to getTransactionalVariable rather than using a request. Add __hash__ so that a transaction can register TransactionalVariable. Make sure that a portal object retains the right object.
Modified:
erp5/trunk/products/ERP5Type/Base.py
erp5/trunk/products/ERP5Type/Cache.py
erp5/trunk/products/ERP5Type/TransactionalVariable.py
erp5/trunk/products/ERP5Type/tests/testTransactionalVariable.py
Modified: erp5/trunk/products/ERP5Type/Base.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Base.py?rev=13817&r1=13816&r2=13817&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Base.py (original)
+++ erp5/trunk/products/ERP5Type/Base.py Fri Mar 30 12:02:36 2007
@@ -675,7 +675,7 @@
going to edit the related object
"""
# Push context to prevent loop
- tv = getTransactionalVariable()
+ tv = getTransactionalVariable(self)
if isinstance(portal_type, list):
portal_type = tuple(portal_type)
acquisition_key = ('_getDefaultAcquiredProperty', self.getPath(), key, base_category,
@@ -794,7 +794,7 @@
"""
# Push context to prevent loop
- tv = getTransactionalVariable()
+ tv = getTransactionalVariable(self)
if isinstance(portal_type, list):
portal_type = tuple(portal_type)
acquisition_key = ('_getAcquiredPropertyList', self.getPath(), key, base_category,
Modified: erp5/trunk/products/ERP5Type/Cache.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Cache.py?rev=13817&r1=13816&r2=13817&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Cache.py (original)
+++ erp5/trunk/products/ERP5Type/Cache.py Fri Mar 30 12:02:36 2007
@@ -225,7 +225,7 @@
def getReadOnlyTransactionCache(context):
"""Get the transaction cache.
"""
- tv = getTransactionalVariable()
+ tv = getTransactionalVariable(context)
try:
return tv['read_only_transaction_cache']
except KeyError:
@@ -234,13 +234,13 @@
def enableReadOnlyTransactionCache(context):
"""Enable the transaction cache.
"""
- tv = getTransactionalVariable()
+ tv = getTransactionalVariable(context)
tv['read_only_transaction_cache'] = {}
def disableReadOnlyTransactionCache(context):
"""Disable the transaction cache.
"""
- tv = getTransactionalVariable()
+ tv = getTransactionalVariable(context)
try:
del tv['read_only_transaction_cache']
except KeyError:
Modified: erp5/trunk/products/ERP5Type/TransactionalVariable.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/TransactionalVariable.py?rev=13817&r1=13816&r2=13817&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/TransactionalVariable.py (original)
+++ erp5/trunk/products/ERP5Type/TransactionalVariable.py Fri Mar 30 12:02:36 2007
@@ -66,13 +66,7 @@
_finalize = None
def _begin(self, *ignored):
- """It is required to attach this instance to somewhere in
- ZODB so that _finish or _abort will be called at the end
- of a transaction. A portal object is used at the moment."""
- # Is there any other way to retrieve a portal object?
- from Products.ERP5Type.Utils import get_request
- portal = get_request()['PARENTS'].getPortalObject()
- portal._v_erp5_transactional_variable = self
+ pass
def _finish(self, *ignored):
self.clear()
@@ -80,16 +74,23 @@
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():
+def getTransactionalVariable(context):
"""Return a transactional variable."""
+ portal = context.portal_url.getPortalObject()
try:
- return transactional_variable_pool.instance
+ 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 transactional_variable_pool.instance
+ return getTransactionalVariable()
Modified: erp5/trunk/products/ERP5Type/tests/testTransactionalVariable.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/testTransactionalVariable.py?rev=13817&r1=13816&r2=13817&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/testTransactionalVariable.py (original)
+++ erp5/trunk/products/ERP5Type/tests/testTransactionalVariable.py Fri Mar 30 12:02:36 2007
@@ -73,7 +73,7 @@
ZopeTestCase._print('\n '+message)
LOG('Testing... ', 0, message)
- tv = getTransactionalVariable()
+ tv = getTransactionalVariable(self.getPortal())
self.failIfEqual(tv, None)
# Test frequently used dict methods. This does not cover everything,
@@ -106,7 +106,7 @@
ZopeTestCase._print('\n '+message)
LOG('Testing... ', 0, message)
- tv = getTransactionalVariable()
+ tv = getTransactionalVariable(self.getPortal())
self.failIfEqual(tv, None)
tv.clear()
@@ -134,7 +134,7 @@
ZopeTestCase._print('\n '+message)
LOG('Testing... ', 0, message)
- tv = getTransactionalVariable()
+ tv = getTransactionalVariable(self.getPortal())
self.failIfEqual(tv, None)
tv.clear()
More information about the Erp5-report
mailing list