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
Sebastien Robin
erp5
Commits
915a2451
Commit
915a2451
authored
Oct 07, 2016
by
iv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5Workflow: PERF improve for loops
parent
08d28458
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
85 additions
and
87 deletions
+85
-87
product/ERP5Workflow/Document/InteractionWorkflow.py
product/ERP5Workflow/Document/InteractionWorkflow.py
+12
-7
product/ERP5Workflow/Document/State.py
product/ERP5Workflow/Document/State.py
+2
-4
product/ERP5Workflow/Document/Workflow.py
product/ERP5Workflow/Document/Workflow.py
+55
-63
product/ERP5Workflow/Document/Worklist.py
product/ERP5Workflow/Document/Worklist.py
+16
-13
No files found.
product/ERP5Workflow/Document/InteractionWorkflow.py
View file @
915a2451
...
...
@@ -95,9 +95,12 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
chained_ptype_list
=
[]
wf_tool
=
getToolByName
(
self
,
'portal_workflow'
)
types_tool
=
getToolByName
(
self
,
'portal_types'
)
for
ptype
in
types_tool
.
objectValues
():
if
self
.
getId
()
in
ptype
.
getTypeWorkflowList
():
chained_ptype_list
.
append
(
ptype
.
getId
())
interaction_workflow_id
=
self
.
getId
()
append
=
chained_ptype_list
.
append
for
portal_type
in
types_tool
.
objectValues
():
if
interaction_workflow_id
in
portal_type
.
getTypeWorkflowList
():
append
(
portal_type
.
getId
())
return
chained_ptype_list
security
.
declarePrivate
(
'listObjectActions'
)
...
...
@@ -208,8 +211,9 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
security
.
declarePrivate
(
'getTransitionIdList'
)
def
getTransitionIdList
(
self
):
id_list
=
[]
append
=
id_list
.
append
for
ob
in
self
.
objectValues
(
portal_type
=
"Interaction"
):
id_list
.
append
(
ob
.
getReference
())
append
(
ob
.
getReference
())
return
id_list
security
.
declarePrivate
(
'notifyWorkflowMethod'
)
...
...
@@ -229,11 +233,11 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
kw
=
kw
.
copy
()
kw
[
'workflow_method_args'
]
=
args
filtered_transition_list
=
[]
append
=
filtered_transition_list
.
append
for
t_id
in
transition_list
:
tdef
=
self
.
_getOb
(
'interaction_'
+
t_id
)
assert
tdef
.
getTriggerType
()
==
TRIGGER_WORKFLOW_METHOD
filtered_transition_list
.
append
(
tdef
.
getId
())
append
(
tdef
.
getId
())
former_status
=
{}
sci
=
StateChangeInfo
(
...
...
@@ -259,6 +263,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
kw
[
'workflow_method_args'
]
=
args
kw
[
'workflow_method_result'
]
=
result
workflow_variable_list
=
self
.
objectValues
(
portal_type
=
'Workflow Variable'
)
for
t_id
in
transition_list
:
tdef
=
self
.
_getOb
(
'interaction_'
+
t_id
)
assert
tdef
.
getTriggerType
()
==
TRIGGER_WORKFLOW_METHOD
...
...
@@ -271,7 +276,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
if
tdef_exprs
is
None
:
tdef_exprs
=
{}
status
=
{}
for
vdef
in
self
.
objectValues
(
portal_type
=
'Workflow Variable'
)
:
for
vdef
in
workflow_variable_list
:
id
=
vdef
.
getId
()
if
not
vdef
.
getStatusIncluded
():
continue
...
...
product/ERP5Workflow/Document/State.py
View file @
915a2451
...
...
@@ -124,10 +124,8 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getDestinationReferenceList'
)
def
getDestinationReferenceList
(
self
):
ref_list
=
[]
for
tr
in
self
.
getDestinationValueList
():
ref_list
.
append
(
tr
.
getReference
())
return
ref_list
return
[
transition
.
getReference
()
for
transition
in
self
.
getDestinationValueList
()]
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getAvailableTypeList'
)
...
...
product/ERP5Workflow/Document/Workflow.py
View file @
915a2451
...
...
@@ -209,32 +209,34 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
def
_checkTransitionGuard
(
self
,
transition
,
document
,
**
kw
):
return
transition
.
checkGuard
(
getSecurityManager
(),
self
,
document
,
**
kw
)
def
_findAutomaticTransition
(
self
,
document
,
sdef
):
tdef
=
None
for
t
in
sdef
.
getDestinationValueList
():
if
t
.
getTriggerType
()
==
TRIGGER_AUTOMATIC
:
if
self
.
_checkTransitionGuard
(
t
,
document
):
tdef
=
t
def
_findAutomaticTransition
(
self
,
document
,
state
):
transition
=
None
checkTransitionGuard
=
self
.
_checkTransitionGuard
for
possible_transition
in
state
.
getDestinationValueList
():
if
possible_transition
.
getTriggerType
()
==
TRIGGER_AUTOMATIC
:
if
checkTransitionGuard
(
possible_transition
,
document
):
transition
=
possible_transition
break
return
t
def
return
t
ransition
security
.
declarePrivate
(
'updateRoleMappingsFor'
)
def
updateRoleMappingsFor
(
self
,
document
):
"""
Changes the object permissions according to the current state.
"""
changed
=
0
changed
=
False
state
=
self
.
_getWorkflowStateOf
(
document
,
id_only
=
False
)
if
state
is
not
None
:
state_permission_list
=
state
.
getAcquirePermissionList
()
for
permission
,
role_list
in
state
.
getStatePermissionRolesDict
().
items
():
# tuple means "don't acquire" in zope internal security and list
# is used when acquisition should be done
if
permission
in
state
.
getAcquirePermissionList
()
:
if
permission
in
state
_permission_list
:
role_list
=
list
(
role_list
)
else
:
role_list
=
tuple
(
role_list
)
if
modifyRolesForPermission
(
document
,
permission
,
role_list
):
changed
=
1
changed
=
True
return
changed
# This method allows to update all objects using one workflow, for example
...
...
@@ -251,20 +253,20 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
type_info_list
=
workflow_tool
.
_listTypeInfo
()
workflow_id
=
self
.
id
portal_type_id_list
=
[]
#
look into old chain_by_type (for compatibility)
append
=
portal_type_id_list
.
append
#
## Compatibility DC Workflow: look into old chain_by_type
for
type_info
in
type_info_list
:
type_info_id
=
type_info
.
getId
()
if
chain_by_type
.
has_key
(
type_info_id
)
and
\
workflow_id
in
chain_by_type
[
type_info_id
]:
portal_type_id_list
.
append
(
type_info_id
)
append
(
type_info_id
)
elif
workflow_id
in
workflow_tool
.
_default_chain
:
portal_type_id_list
.
append
(
type_info_id
)
append
(
type_info_id
)
# check the workflow defined on the portal type objects
for
portal_type
in
self
.
getPortalObject
().
portal_types
.
objectValues
(
portal_type
=
'Base Type'
):
for
portal_type
in
self
.
portal_types
.
objectValues
(
portal_type
=
'Base Type'
):
if
workflow_id
in
portal_type
.
getTypeWorkflowList
():
portal_type_id_list
.
append
(
portal_type
.
getId
())
append
(
portal_type
.
getId
())
if
portal_type_id_list
:
object_list
=
self
.
portal_catalog
(
portal_type
=
portal_type_id_list
,
limit
=
None
)
...
...
@@ -350,7 +352,8 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
sdef
=
self
.
_getWorkflowStateOf
(
document
,
id_only
=
0
)
if
sdef
is
None
:
return
None
res
=
[]
object_action_list
=
[]
append
=
object_action_list
.
append
for
tid
in
sdef
.
getDestinationIdList
():
tdef
=
self
.
_getOb
(
id
=
tid
)
...
...
@@ -360,7 +363,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
fmt_data
=
TemplateDict
()
fmt_data
.
_push
(
info
)
fmt_data
.
_push
({
'transition_id'
:
tdef
.
getReference
()})
res
.
append
((
tid
,
{
append
((
tid
,
{
'id'
:
tdef
.
getReference
(),
'name'
:
tdef
.
getActionName
()
%
fmt_data
,
'url'
:
str
(
tdef
.
getAction
())
%
fmt_data
,
...
...
@@ -369,9 +372,9 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
'category'
:
tdef
.
getActionType
(),
'transition'
:
tdef
}))
fmt_data
.
_pop
()
res
.
sort
()
object_action_list
.
sort
()
return
[
result
[
1
]
for
result
in
res
]
return
[
result
[
1
]
for
result
in
object_action_list
]
def
getWorklistVariableMatchDict
(
self
,
info
,
check_guard
=
True
):
"""
...
...
@@ -384,12 +387,10 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
portal
=
self
.
getPortalObject
()
def
getPortalTypeListForWorkflow
(
workflow_id
):
portal_type_list
=
[]
for
type_info
in
portal
.
portal_types
.
objectValues
():
portal_type
=
type_info
.
id
if
workflow_id
in
type_info
.
getTypeWorkflowList
():
portal_type_list
.
append
(
portal_type
)
return
portal_type_list
return
[
type_info
.
id
for
type_info
in
portal
.
portal_types
.
objectValues
()
if
workflow_id
in
type_info
.
getTypeWorkflowList
()]
_getPortalTypeListForWorkflow
=
CachingMethod
(
getPortalTypeListForWorkflow
,
id
=
'_getPortalTypeListForWorkflow'
,
cache_factory
=
'erp5_ui_long'
)
...
...
@@ -525,16 +526,12 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
return
state
def
getVariableValueDict
(
self
):
variable_dict
=
{}
for
vdef
in
self
.
objectValues
(
portal_type
=
"Workflow Variable"
):
variable_dict
[
vdef
.
getReference
()]
=
vdef
return
variable_dict
return
{
variable
.
getReference
():
variable
for
variable
in
self
.
objectValues
(
portal_type
=
"Workflow Variable"
)}
def
getVariableIdList
(
self
):
id_list
=
[]
for
ob
in
self
.
objectValues
(
portal_type
=
"Workflow Variable"
):
id_list
.
append
(
ob
.
getReference
())
return
id_list
return
[
variable
.
getReference
()
for
variable
in
self
.
objectValues
(
portal_type
=
"Workflow Variable"
)]
def
getStateValueById
(
self
,
stated_id
):
return
self
.
_getOb
(
'state_'
+
stated_id
,
default
=
None
)
...
...
@@ -543,19 +540,15 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
return
self
.
objectValues
(
portal_type
=
"State"
)
def
getStateIdList
(
self
):
id_list
=
[]
for
ob
in
self
.
objectValues
(
portal_type
=
"State"
):
id_list
.
append
(
ob
.
getReference
())
return
id_list
return
[
state
.
getReference
()
for
state
in
self
.
objectValues
(
portal_type
=
"State"
)]
def
getWorklistValueList
(
self
):
return
self
.
objectValues
(
portal_type
=
"Worklist"
)
def
getWorklistIdList
():
id_list
=
[]
for
ob
in
self
.
objectValues
(
portal_type
=
"Worklist"
):
id_list
.
append
(
ob
.
getReference
())
return
id_list
return
[
worklist
.
getReference
()
for
worklist
in
self
.
objectValues
(
portal_type
=
"Worklist"
)]
def
getWorklistValueById
(
self
,
worklist_reference
):
return
self
.
_getOb
(
'worklist_'
+
worklist_reference
,
None
)
...
...
@@ -567,7 +560,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
return
self
.
objectValues
(
portal_type
=
"Transition"
)
def
getTransitionIdList
(
self
):
return
[
ob
.
getReference
()
for
ob
return
[
transition
.
getReference
()
for
transition
in
self
.
objectValues
(
portal_type
=
"Transition"
)]
def
getScriptValueList
(
self
):
...
...
@@ -664,7 +657,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
for
script
in
script_value_list
:
# Pass lots of info to the script in a single parameter.
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
()))
try
:
script
(
sci
)
# May throw an exception.
...
...
@@ -697,6 +690,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
object
.
REQUEST
.
other
.
update
(
form_kw
)
kwargs
=
form_kw
# XXX(WORKFLOW) check this for loop
for
vdef
in
self
.
objectValues
(
portal_type
=
'Workflow Variable'
):
id
=
vdef
.
getId
()
variable_reference
=
vdef
.
getReference
()
...
...
@@ -756,9 +750,10 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
kwargs
=
form_kw
sci
=
StateChangeInfo
(
document
,
self
,
former_status
,
tdef
,
old_sdef
,
new_sdef
,
kwargs
)
old_state_destination_list
=
old_sdef
.
getDestinationValueList
()
for
script
in
script_value_list
:
# Script can be either script or workflow method
if
script
in
old_s
def
.
getDestinationValueList
()
and
\
if
script
in
old_s
tate_destination_list
and
\
self
.
_getOb
(
script
.
id
).
getTriggerType
()
==
TRIGGER_WORKFLOW_METHOD
:
getattr
(
document
,
convertToMixedCase
(
self
.
_getOb
(
script
.
id
).
getReference
()))()
else
:
...
...
@@ -1072,12 +1067,9 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
"""
Get list of portal types for workflow.
"""
result
=
[]
workflow_id
=
self
.
getId
()
for
portal_type
in
self
.
getPortalObject
().
portal_types
.
objectValues
():
if
workflow_id
in
portal_type
.
getTypeWorkflowList
():
result
.
append
(
portal_type
.
getId
())
return
result
return
[
portal_type
.
getId
()
for
portal_type
in
self
.
portal_types
.
objectValues
()
if
workflow_id
in
portal_type
.
getTypeWorkflowList
()]
def
_executeMetaTransition
(
self
,
ob
,
new_state_id
):
"""
...
...
@@ -1176,19 +1168,19 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
# Always provide the state variable.
state_var
=
self
.
getStateVariable
()
status
=
self
.
getCurrentStatusDict
(
ob
)
for
v
def_ref
,
vdef
in
self
.
getVariableValueDict
().
iteritems
():
if
vdef
.
getForCatalog
():
variable_expression
=
vdef
.
getVariableExpression
()
if
status
.
has_key
(
vdef_ref
):
value
=
status
[
vdef_ref
]
# Not set yet. Use a default.
elif
variable_expression
is
not
None
:
ec
=
createExprContext
(
StateChangeInfo
(
ob
,
self
,
status
))
# convert string to expression before execute it.
value
=
Expression
(
variable_expression
)(
ec
)
else
:
value
=
vdef
.
getVariableValue
()
for
v
ariable_id
,
variable
in
self
.
getVariableValueDict
().
iteritems
():
if
variable
.
getForCatalog
():
variable_expression
=
variable
.
getVariableExpression
()
if
status
.
has_key
(
variable_id
):
value
=
status
[
variable_id
]
# Not set yet. Use a default.
elif
variable_expression
is
not
None
:
ec
=
createExprContext
(
StateChangeInfo
(
ob
,
self
,
status
))
# convert string to expression before execute it.
value
=
Expression
(
variable_expression
)(
ec
)
else
:
value
=
variable
.
getVariableValue
()
if
hasattr
(
self
,
'getSourceValue'
):
if
self
.
getSourceValue
()
is
not
None
:
initial_state
=
self
.
getSourceValue
().
getReference
()
...
...
product/ERP5Workflow/Document/Worklist.py
View file @
915a2451
...
...
@@ -75,21 +75,20 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject,
)
def getAvailableCatalogVars(self):
res = []
res.append(self.getParentValue().getStateVariable())
for vdef in self.getParentValue().contentValues(portal_type="Workflow Variable"):
if vdef.getForCatalog():
res.append(vdef.getId())
for vdef in self.objectValues():
res.append(vdef.getId())
res.sort()
return res
parent = self.getParentValue()
res = [parent.getStateVariable()]
res += [variable.getId() for variable in self.objectValues()]
res += [variable for variable in
parent.contentValues(portal_type="Workflow Variable")
if variable.getForCatalog()]
res.sort()
return res
def updateDynamicVariable(self):
# Keep worklist variables updating, correspond to workflow variables.
# In the new workflow, we may not need this function for the moment.
res = []
# XXX(WORKFLOW): is there a reason not to return self.objectValues() here?
for worklist_variable_value in self.objectValues():
res.append(worklist_variable_value)
return res
...
...
@@ -107,16 +106,20 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject,
variable_id = variable_value.getId()
workflow_variable_id_list.append(variable_id)
worklist_variable_value = self._getOb(variable_id, None)
if worklist_variable_value is None and variable_value.getForCatalog() == 1 and variable_id not in default_variable_id_list:
if (worklist_variable_value is None
and variable_value.getForCatalog() == 1
and variable_id not in default_variable_id_list):
variable_value_ref = variable_value.getReference()
worklist_variable_value = self.newContent(portal_type='
Worklist
Variable
')
worklist_variable_value.setReference(variable_value_ref)
worklist_variable_value.setVariableExpression(variable_value.getVariableExpression())
worklist_variable_value.setVariableValue(variable_value.getVariableValue())
res.append(worklist_variable_value)
if worklist_variable_value and worklist_variable_value not in res and variable_value.getForCatalog() == 1:
if (worklist_variable_value and worklist_variable_value not in res
and variable_value.getForCatalog() == 1):
res.append(worklist_variable_value)
if worklist_variable_value in res and variable_value.getForCatalog() == 0:
if (worklist_variable_value in res
and variable_value.getForCatalog() == 0):
self._delObject(variable_id)
res.remove(worklist_variable_value)
...
...
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