Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
erp5
Commits
b8881e47
Commit
b8881e47
authored
Dec 09, 2016
by
iv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5Workflow: call getStateChangeInformation once if multiple after/before/... scripts
parent
2b58c8fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
18 deletions
+33
-18
product/ERP5Workflow/Document/InteractionWorkflow.py
product/ERP5Workflow/Document/InteractionWorkflow.py
+18
-11
product/ERP5Workflow/Document/Workflow.py
product/ERP5Workflow/Document/Workflow.py
+15
-7
No files found.
product/ERP5Workflow/Document/InteractionWorkflow.py
View file @
b8881e47
...
@@ -259,11 +259,13 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
...
@@ -259,11 +259,13 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
sci
=
StateChangeInfo
(
sci
=
StateChangeInfo
(
ob
,
self
,
former_status
,
tdef
,
None
,
None
,
kwargs
=
kw
)
ob
,
self
,
former_status
,
tdef
,
None
,
None
,
kwargs
=
kw
)
for
script
in
tdef
.
getBeforeScriptValueList
():
script_value_list
=
tdef
.
getBeforeScriptValueList
()
if
script_value_list
:
script_context
=
self
.
_asScriptContext
()
for
script
in
script_value_list
:
if
script
:
if
script
:
script_context
=
self
.
_asScriptContext
()
script
=
getattr
(
script_context
,
script
.
id
)
script
=
getattr
(
script_context
,
script
.
id
)
script
(
sci
)
script
(
sci
)
# May throw an exception.
return
filtered_transition_list
return
filtered_transition_list
def
notifySuccess
(
self
,
ob
,
transition_list
,
result
,
args
=
None
,
kw
=
None
):
def
notifySuccess
(
self
,
ob
,
transition_list
,
result
,
args
=
None
,
kw
=
None
):
...
@@ -326,12 +328,13 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
...
@@ -326,12 +328,13 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
ob
,
self
,
former_status
,
tdef
,
None
,
None
,
kwargs
=
kw
)
ob
,
self
,
former_status
,
tdef
,
None
,
None
,
kwargs
=
kw
)
# Execute the "after" script.
# Execute the "after" script.
after_script_list
=
tdef
.
getAfterScriptValueList
()
after_script_value_list
=
tdef
.
getAfterScriptValueList
()
for
script
in
after_script_list
:
if
after_script_value_list
:
script_context
=
self
.
_asScriptContext
()
for
script
in
after_script_value_list
:
if
script
:
if
script
:
script_context
=
self
.
_asScriptContext
()
script
=
getattr
(
script_context
,
script
.
id
)
script
=
getattr
(
script_context
,
script
.
id
)
script
(
sci
)
# May throw an exception
script
(
sci
)
# May throw an exception
.
# Queue the "Before Commit" scripts
# Queue the "Before Commit" scripts
sm
=
getSecurityManager
()
sm
=
getSecurityManager
()
...
@@ -342,10 +345,12 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
...
@@ -342,10 +345,12 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
# Execute "activity" scripts
# Execute "activity" scripts
activity_script_list
=
tdef
.
getActivateScriptValueList
()
activity_script_list
=
tdef
.
getActivateScriptValueList
()
if
activity_script_list
:
script_context
=
self
.
_asScriptContext
()
for
script
in
activity_script_list
:
for
script
in
activity_script_list
:
self
.
activate
(
activity
=
'SQLQueue'
)
\
self
.
activate
(
activity
=
'SQLQueue'
)
\
.
activeScript
(
script
.
id
,
ob
.
getRelativeUrl
(),
.
activeScript
(
script
.
id
,
ob
.
getRelativeUrl
(),
status
,
tdef
.
getId
(),
s
tatus
,
tdef
.
getId
()
)
s
cript_context
=
script_context
)
def
_before_commit
(
self
,
sci
,
script_name
,
security_manager
):
def
_before_commit
(
self
,
sci
,
script_name
,
security_manager
):
# check the object still exists before calling the script
# check the object still exists before calling the script
...
@@ -364,8 +369,10 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
...
@@ -364,8 +369,10 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
finally
:
finally
:
setSecurityManager
(
current_security_manager
)
setSecurityManager
(
current_security_manager
)
def
activeScript
(
self
,
script_name
,
ob_url
,
former_status
,
tdef_id
):
def
activeScript
(
self
,
script_name
,
ob_url
,
former_status
,
tdef_id
,
script_context
=
self
.
_asScriptContext
()
script_context
=
None
):
if
script_context
is
None
:
script_context
=
self
.
_asScriptContext
()
script
=
getattr
(
script_context
,
script_name
)
script
=
getattr
(
script_context
,
script_name
)
ob
=
self
.
unrestrictedTraverse
(
ob_url
)
ob
=
self
.
unrestrictedTraverse
(
ob_url
)
tdef
=
self
.
_getOb
(
tdef_id
)
tdef
=
self
.
_getOb
(
tdef_id
)
...
...
product/ERP5Workflow/Document/Workflow.py
View file @
b8881e47
...
@@ -734,12 +734,13 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject, CacheCookieMixin):
...
@@ -734,12 +734,13 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject, CacheCookieMixin):
kwargs
=
form_kw
kwargs
=
form_kw
sci
=
StateChangeInfo
(
document
,
self
,
former_status
,
tdef
,
old_sdef
,
sci
=
StateChangeInfo
(
document
,
self
,
former_status
,
tdef
,
old_sdef
,
new_sdef
,
kwargs
)
new_sdef
,
kwargs
)
if
script_value_list
:
script_context
=
self
.
_asScriptContext
()
for
script
in
script_value_list
:
for
script
in
script_value_list
:
# Pass lots of info to the script in a single parameter.
# Pass lots of info to the script in a single parameter.
if
script
.
getPortalType
()
!=
'Workflow Script'
:
if
script
.
getPortalType
()
!=
'Workflow Script'
:
raise
NotImplementedError
(
'Unsupported Script %s for state %s'
%
raise
NotImplementedError
(
'Unsupported Script %s for state %s'
%
(
script
.
id
,
old_sdef
.
getReference
()))
(
script
.
id
,
old_sdef
.
getReference
()))
script_context
=
self
.
_asScriptContext
()
script
=
getattr
(
script_context
,
script
.
id
)
script
=
getattr
(
script_context
,
script
.
id
)
try
:
try
:
script
(
sci
)
# May throw an exception.
script
(
sci
)
# May throw an exception.
...
@@ -754,7 +755,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject, CacheCookieMixin):
...
@@ -754,7 +755,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject, CacheCookieMixin):
# update variables
# update variables
state_values
=
None
state_values
=
None
# seems state variable is not used in new workflow.
# seems state variable is not used in new workflow.
object
=
self
.
getStateChangeInformation
(
document
,
source_value
)
object
_context
=
None
if
new_sdef
is
not
None
:
if
new_sdef
is
not
None
:
state_values
=
getattr
(
new_sdef
,
'var_values'
,
None
)
state_values
=
getattr
(
new_sdef
,
'var_values'
,
None
)
if
state_values
is
None
:
if
state_values
is
None
:
...
@@ -769,7 +770,9 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject, CacheCookieMixin):
...
@@ -769,7 +770,9 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject, CacheCookieMixin):
# Update all transition variables
# Update all transition variables
if
form_kw
is
not
None
:
if
form_kw
is
not
None
:
object
.
REQUEST
.
other
.
update
(
form_kw
)
if
object_context
is
None
:
object_context
=
self
.
getStateChangeInformation
(
document
,
source_value
)
object_context
.
REQUEST
.
other
.
update
(
form_kw
)
kwargs
=
form_kw
kwargs
=
form_kw
for
vdef
in
self
.
objectValues
(
portal_type
=
'Workflow Variable'
):
for
vdef
in
self
.
objectValues
(
portal_type
=
'Workflow Variable'
):
...
@@ -790,7 +793,9 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject, CacheCookieMixin):
...
@@ -790,7 +793,9 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject, CacheCookieMixin):
if
variable_expression
is
not
None
:
if
variable_expression
is
not
None
:
expr
=
variable_expression
expr
=
variable_expression
else
:
else
:
value
=
vdef
.
getVariableValue
(
object
=
object
)
if
object_context
is
None
:
object_context
=
self
.
getStateChangeInformation
(
document
,
source_value
)
value
=
vdef
.
getVariableValue
(
object
=
object_context
)
if
expr
not
in
(
None
,
''
):
if
expr
not
in
(
None
,
''
):
# Evaluate an expression.
# Evaluate an expression.
if
econtext
is
None
:
if
econtext
is
None
:
...
@@ -830,15 +835,18 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject, CacheCookieMixin):
...
@@ -830,15 +835,18 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject, CacheCookieMixin):
sci
=
StateChangeInfo
(
document
,
self
,
former_status
,
tdef
,
old_sdef
,
sci
=
StateChangeInfo
(
document
,
self
,
former_status
,
tdef
,
old_sdef
,
new_sdef
,
kwargs
)
new_sdef
,
kwargs
)
old_state_destination_list
=
old_sdef
.
getDestinationValueList
()
old_state_destination_list
=
old_sdef
.
getDestinationValueList
()
script_context
=
None
for
script
in
script_value_list
:
for
script
in
script_value_list
:
# Script can be either script or workflow method
# Script can be either script or workflow method
script_value
=
self
.
_getOb
(
script
.
id
)
if
script
in
old_state_destination_list
and
\
if
script
in
old_state_destination_list
and
\
s
elf
.
_getOb
(
script
.
id
)
.
getTriggerType
()
==
TRIGGER_WORKFLOW_METHOD
:
s
cript_value
.
getTriggerType
()
==
TRIGGER_WORKFLOW_METHOD
:
getattr
(
document
,
convertToMixedCase
(
s
elf
.
_getOb
(
script
.
id
)
.
getReference
()))()
getattr
(
document
,
convertToMixedCase
(
s
cript_value
.
getReference
()))()
else
:
else
:
# Pass lots of info to the script in a single parameter.
# Pass lots of info to the script in a single parameter.
if
script
.
getPortalType
()
==
'Workflow Script'
:
if
script
.
getPortalType
()
==
'Workflow Script'
:
script_context
=
self
.
_asScriptContext
()
if
script_context
is
None
:
script_context
=
self
.
_asScriptContext
()
script
=
getattr
(
script_context
,
script
.
id
)
script
=
getattr
(
script_context
,
script
.
id
)
script
(
sci
)
# May throw an exception.
script
(
sci
)
# May throw an exception.
...
...
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