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