Commit 8d213f3c authored by Julien Muchembled's avatar Julien Muchembled

CMFActivity: new context manager for default activate parameters

parent 511d09c8
......@@ -28,6 +28,7 @@
import ExtensionClass
import warnings
from contextlib import contextmanager
from AccessControl import ClassSecurityInfo
from Acquisition import aq_base
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
......@@ -155,6 +156,30 @@ class ActiveObject(ExtensionClass.Base):
if path:
return self.unrestrictedTraverse(path)
# XXX: Use something else than 'id(aq_base(self)))' because it
# would fail if object is ejected from connection cache.
@contextmanager
def defaultActivateParameterDict(self, parameter_dict, placeless=False):
# XXX: Should we be more strict about reentrant calls ?
# - should they be forbidden ?
# - or should we merge entries ?
if parameter_dict is None:
yield
else:
tv = getTransactionalVariable()
key = (_DEFAULT_ACTIVATE_PARAMETER_KEY,) if placeless else \
(_DEFAULT_ACTIVATE_PARAMETER_KEY, id(aq_base(self)))
old_kw = tv.get(key)
tv[key] = parameter_dict.copy()
try:
yield
finally:
if old_kw is None:
del tv[key]
else:
tv[key] = old_kw
def setDefaultActivateParameterDict(self, parameter_dict, placeless=False):
# This method sets the default keyword parameters to activate. This is
# useful when you need to specify special parameters implicitly (e.g. to
......
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