Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Arnaud Fontaine
erp5
Commits
8d213f3c
Commit
8d213f3c
authored
May 03, 2012
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CMFActivity: new context manager for default activate parameters
parent
511d09c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
product/CMFActivity/ActiveObject.py
product/CMFActivity/ActiveObject.py
+25
-0
No files found.
product/CMFActivity/ActiveObject.py
View file @
8d213f3c
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment