Commit 4a0f9f98 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Use a transactional variable instead of a transaction object for acquisition...

Use a transactional variable instead of a transaction object for acquisition stacks. Remove unneeded imports.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13755 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1b3b7b62
...@@ -28,9 +28,8 @@ ...@@ -28,9 +28,8 @@
from struct import unpack from struct import unpack
import warnings import warnings
import ExtensionClass
from Globals import InitializeClass, DTMLFile, PersistentMapping from Globals import InitializeClass, DTMLFile
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from AccessControl.Permission import pname, Permission from AccessControl.Permission import pname, Permission
from AccessControl.PermissionRole import rolesForPermissionOn from AccessControl.PermissionRole import rolesForPermissionOn
...@@ -56,7 +55,7 @@ from Products.ERP5Type.Cache import CachingMethod, clearCache, getReadOnlyTransa ...@@ -56,7 +55,7 @@ from Products.ERP5Type.Cache import CachingMethod, clearCache, getReadOnlyTransa
from Products.CMFCore.WorkflowCore import ObjectDeleted from Products.CMFCore.WorkflowCore import ObjectDeleted
from Accessor import WorkflowState from Accessor import WorkflowState
from Products.ERP5Type.Log import log as unrestrictedLog from Products.ERP5Type.Log import log as unrestrictedLog
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from ZopePatch import ERP5PropertyManager from ZopePatch import ERP5PropertyManager
from CopySupport import CopyContainer, CopyError,\ from CopySupport import CopyContainer, CopyError,\
...@@ -69,22 +68,14 @@ from Products.ERP5Type.Accessor.TypeDefinition import asDate ...@@ -69,22 +68,14 @@ from Products.ERP5Type.Accessor.TypeDefinition import asDate
from string import join from string import join
import sys import sys
import psyco import psyco
import traceback
from cStringIO import StringIO from cStringIO import StringIO
from socket import gethostname, gethostbyaddr from socket import gethostname, gethostbyaddr
import random import random
from DateTime import DateTime
import inspect import inspect
from pprint import pformat from pprint import pformat
try:
from transaction import get as get_transaction
except ImportError:
pass
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from zLOG import LOG, INFO, ERROR, WARNING from zLOG import LOG, INFO, ERROR, WARNING
...@@ -682,21 +673,20 @@ class Base( CopyContainer, ...@@ -682,21 +673,20 @@ class Base( CopyContainer,
Other case : we want to change the phone number of a related object without Other case : we want to change the phone number of a related object without
going to edit the related object going to edit the related object
""" """
# Push context to prevent loop # Push context to prevent loop
# We use TRANSACTION but should use REQUEST tv = getTransactionalVariable()
from Globals import get_request
TRANSACTION = get_transaction()
if not hasattr(TRANSACTION, '_erp5_acquisition_stack'): TRANSACTION._erp5_acquisition_stack = {}
if isinstance(portal_type, list): if isinstance(portal_type, list):
portal_type = tuple(portal_type) portal_type = tuple(portal_type)
acquisition_key = ('_getDefaultAcquiredProperty', self.getPath(), key, base_category, acquisition_key = ('_getDefaultAcquiredProperty', self.getPath(), key, base_category,
portal_type, copy_value, mask_value, sync_value, portal_type, copy_value, mask_value, sync_value,
accessor_id, depends, storage_id, alt_accessor_id, is_list_type, is_tales_type) accessor_id, depends, storage_id, alt_accessor_id, is_list_type, is_tales_type)
if TRANSACTION._erp5_acquisition_stack.has_key(acquisition_key): return null_value if acquisition_key in tv:
TRANSACTION._erp5_acquisition_stack[acquisition_key] = 1 return null_value
tv[acquisition_key] = 1
try:
if storage_id is None: storage_id=key if storage_id is None: storage_id=key
#LOG("Get Acquired Property storage_id",0,str(storage_id)) #LOG("Get Acquired Property storage_id",0,str(storage_id))
# Test presence of attribute without acquisition # Test presence of attribute without acquisition
...@@ -710,7 +700,6 @@ class Base( CopyContainer, ...@@ -710,7 +700,6 @@ class Base( CopyContainer,
# If we hold an attribute and mask_value is set, return the attribute # If we hold an attribute and mask_value is set, return the attribute
if mask_value and value is not None: if mask_value and value is not None:
# Pop context # Pop context
del TRANSACTION._erp5_acquisition_stack[acquisition_key]
if is_tales_type: if is_tales_type:
expression = Expression(value) expression = Expression(value)
econtext = createExpressionContext(self) econtext = createExpressionContext(self)
...@@ -758,8 +747,6 @@ class Base( CopyContainer, ...@@ -758,8 +747,6 @@ class Base( CopyContainer,
else: else:
result = None result = None
if result is not None: if result is not None:
# Pop context
del TRANSACTION._erp5_acquisition_stack[acquisition_key]
return result return result
else: else:
#LOG("alt_accessor_id",0,str(alt_accessor_id)) #LOG("alt_accessor_id",0,str(alt_accessor_id))
...@@ -774,28 +761,24 @@ class Base( CopyContainer, ...@@ -774,28 +761,24 @@ class Base( CopyContainer,
if isinstance(result, (list, tuple)): if isinstance(result, (list, tuple)):
# We must provide the first element of the alternate result # We must provide the first element of the alternate result
if len(result) > 0: if len(result) > 0:
# Pop context
del TRANSACTION._erp5_acquisition_stack[acquisition_key]
return result[0] return result[0]
else: else:
# Pop context
del TRANSACTION._erp5_acquisition_stack[acquisition_key]
return result return result
else: else:
# Pop context
del TRANSACTION._erp5_acquisition_stack[acquisition_key]
# Result is a simple type # Result is a simple type
return result return result
if copy_value: if copy_value:
# Pop context
del TRANSACTION._erp5_acquisition_stack[acquisition_key]
return getattr(self,storage_id, default_value) return getattr(self,storage_id, default_value)
else: else:
# Pop context
del TRANSACTION._erp5_acquisition_stack[acquisition_key]
# Return the default value defined at the class level XXXXXXXXXXXXXXX # Return the default value defined at the class level XXXXXXXXXXXXXXX
return default_value return default_value
finally:
# Pop the acquisition context.
try:
del tv[acquisition_key]
except KeyError:
pass
def _getAcquiredPropertyList(self, key, default_value, null_value, def _getAcquiredPropertyList(self, key, default_value, null_value,
base_category, portal_type=None, copy_value=0, mask_value=0, sync_value=0, append_value=0, base_category, portal_type=None, copy_value=0, mask_value=0, sync_value=0, append_value=0,
...@@ -811,20 +794,21 @@ class Base( CopyContainer, ...@@ -811,20 +794,21 @@ class Base( CopyContainer,
""" """
# Push context to prevent loop # Push context to prevent loop
from Globals import get_request tv = getTransactionalVariable()
TRANSACTION = get_transaction() if isinstance(portal_type, list):
if not hasattr(TRANSACTION, '_erp5_acquisition_stack'): TRANSACTION._erp5_acquisition_stack = {} portal_type = tuple(portal_type)
acquisition_key = ('_getAcquiredPropertyList', self.getPath(), key, base_category, acquisition_key = ('_getAcquiredPropertyList', self.getPath(), key, base_category,
portal_type, copy_value, mask_value, sync_value, portal_type, copy_value, mask_value, sync_value,
accessor_id, depends, storage_id, alt_accessor_id, is_list_type, is_tales_type) accessor_id, depends, storage_id, alt_accessor_id, is_list_type, is_tales_type)
if TRANSACTION._erp5_acquisition_stack.has_key(acquisition_key): return null_value if acquisition_key in tv:
TRANSACTION._erp5_acquisition_stack[acquisition_key] = 1 return null_value
tv[acquisition_key] = 1
try:
if storage_id is None: storage_id=key if storage_id is None: storage_id=key
value = getattr(self, storage_id, None) value = getattr(self, storage_id, None)
if mask_value and value is not None: if mask_value and value is not None:
# Pop context
del TRANSACTION._erp5_acquisition_stack[acquisition_key]
if is_tales_type: if is_tales_type:
expression = Expression(value) expression = Expression(value)
econtext = createExpressionContext(self) econtext = createExpressionContext(self)
...@@ -858,19 +842,19 @@ class Base( CopyContainer, ...@@ -858,19 +842,19 @@ class Base( CopyContainer,
if copy_value: if copy_value:
if not hasattr(self, storage_id): if not hasattr(self, storage_id):
setattr(self, storage_id, value) setattr(self, storage_id, value)
# Pop context
del TRANSACTION._erp5_acquisition_stack[acquisition_key]
return value return value
else: else:
# ????? # ?????
if copy_value: if copy_value:
# Pop context
del TRANSACTION._erp5_acquisition_stack[acquisition_key]
return getattr(self,storage_id, default_value) return getattr(self,storage_id, default_value)
else: else:
# Pop context
del TRANSACTION._erp5_acquisition_stack[acquisition_key]
return default_value return default_value
finally:
# Pop the acquisition context.
try:
del tv[acquisition_key]
except KeyError:
pass
security.declareProtected( Permissions.AccessContentsInformation, 'getProperty' ) security.declareProtected( Permissions.AccessContentsInformation, 'getProperty' )
def getProperty(self, key, d=_MARKER, **kw): def getProperty(self, key, d=_MARKER, **kw):
......
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