Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5_fork
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eteri
erp5_fork
Commits
6119445c
Commit
6119445c
authored
Mar 30, 2015
by
wenjie.zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Interaction.py: complete the execution part.
parent
c0d00075
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
1 deletion
+95
-1
product/ERP5Workflow/Document/Interaction.py
product/ERP5Workflow/Document/Interaction.py
+95
-1
No files found.
product/ERP5Workflow/Document/Interaction.py
View file @
6119445c
...
...
@@ -26,7 +26,7 @@
#
##############################################################################
from
AccessControl
import
ClassSecurityInfo
from
AccessControl
import
getSecurityManager
,
ClassSecurityInfo
from
Products.ERP5Type
import
Permissions
,
PropertySheet
from
Products.ERP5Type.XMLObject
import
XMLObject
from
Products.ERP5Type.Globals
import
PersistentMapping
...
...
@@ -53,6 +53,7 @@ class Interaction(XMLObject):
managed_role
=
()
erp5_permission_roles
=
{}
# { permission: [role] or (role,) }
manager_bypass
=
0
method_id
=
()
trigger_type
=
TRIGGER_WORKFLOW_METHOD
script_name
=
()
# Executed before transition
after_script_name
=
()
# Executed after transition
...
...
@@ -116,6 +117,99 @@ class Interaction(XMLObject):
elif
self
.
guard
.
expr
!=
self
.
getExpression
():
self
.
guard
.
expr
=
self
.
getExpression
()
def
execute
(
self
,
ob
,
workflow
,
result
,
args
=
None
,
kw
=
None
):
### zwj: What will be done this part
### this part shoud be called in Base.py as transition be called.
# 1: execute before script;
# 2: execute after script;
# 3: Queue before commit script;
# 4: execute activity script.
workflow
=
self
.
getParent
()
assert
self
.
trigger_type
==
TRIGGER_WORKFLOW_METHOD
# Initialize variables
former_status
=
workflow
.
_getStatusOf
(
ob
)
econtext
=
None
sci
=
None
# Update variables.
tdef_exprs
=
self
.
var_exprs
if
tdef_exprs
is
None
:
tdef_exprs
=
{}
status
=
{}
for
vdef
in
workflow
.
objectValues
(
portal_type
=
'Variable'
):
id
=
vdef
.
getId
()
if
not
vdef
.
for_status
:
continue
expr
=
None
if
id
in
tdef_exprs
:
expr
=
tdef_exprs
[
id
]
elif
not
vdef
.
update_always
and
id
in
former_status
:
# Preserve former value
value
=
former_status
[
id
]
else
:
if
vdef
.
default_expr
is
not
None
:
expr
=
vdef
.
default_expr
else
:
value
=
vdef
.
default_value
if
expr
is
not
None
:
# Evaluate an expression.
if
econtext
is
None
:
# Lazily create the expression context.
if
sci
is
None
:
sci
=
StateChangeInfo
(
ob
,
workflow
,
former_status
,
self
,
None
,
None
,
None
)
econtext
=
createExprContext
(
sci
)
value
=
expr
(
econtext
)
status
[
id
]
=
value
sci
=
StateChangeInfo
(
ob
,
worfklow
,
former_status
,
self
,
None
,
None
,
kwargs
=
kw
)
# Execute the "after" script.
for
script_name
in
self
.
after_script_name
:
script
=
workflow
.
_getOb
(
script_name
)
# Pass lots of info to the script in a single parameter.
script
(
sci
)
# May throw an exception
# Queue the "Before Commit" scripts
sm
=
getSecurityManager
()
for
script_name
in
self
.
before_commit_script_name
:
transaction
.
get
().
addBeforeCommitHook
(
self
.
_before_commit
,
(
sci
,
script_name
,
sm
))
# Execute "activity" scripts
for
script_name
in
self
.
activate_script_name
:
workflow
.
activate
(
activity
=
'SQLQueue'
)
\
.
activeScript
(
script_name
,
ob
.
getRelativeUrl
(),
status
,
self
.
getId
())
def
_before_commit
(
self
,
sci
,
script_name
,
security_manager
):
# check the object still exists before calling the script
ob
=
sci
.
object
workflow
=
self
.
getParent
()
while
ob
.
isTempObject
():
ob
=
ob
.
getParentValue
()
if
aq_base
(
self
.
unrestrictedTraverse
(
ob
.
getPhysicalPath
(),
None
))
is
\
aq_base
(
ob
):
current_security_manager
=
getSecurityManager
()
try
:
# Who knows what happened to the authentication context
# between here and when the interaction was executed... So we
# need to switch to the security manager as it was back then
setSecurityManager
(
security_manager
)
workflow
.
_getOb
(
script_name
)(
sci
)
finally
:
setSecurityManager
(
current_security_manager
)
def
activeScript
(
self
,
script_name
,
ob_url
,
status
):
workflow
=
self
.
getParent
()
script
=
workflow
.
_getOb
(
script_name
)
ob
=
self
.
unrestrictedTraverse
(
ob_url
)
sci
=
StateChangeInfo
(
ob
,
workflow
,
status
,
self
,
None
,
None
,
None
)
script
(
sci
)
def
getVarExprText
(
self
,
id
):
if
not
self
.
var_exprs
:
return
''
...
...
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