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
32ff9e6d
Commit
32ff9e6d
authored
Jul 13, 2016
by
iv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5Workflow: some refactoring on dc_workflow_asERP5Object
parent
151eb74a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
53 deletions
+51
-53
bt5/erp5_workflow/SkinTemplateItem/portal_skins/erp5_workflow/WorkflowTool_convertWorkflow.xml
...rtal_skins/erp5_workflow/WorkflowTool_convertWorkflow.xml
+1
-1
product/ERP5Type/tests/ERP5TypeTestCase.py
product/ERP5Type/tests/ERP5TypeTestCase.py
+2
-2
product/ERP5Workflow/Tool/WorkflowTool.py
product/ERP5Workflow/Tool/WorkflowTool.py
+48
-50
No files found.
bt5/erp5_workflow/SkinTemplateItem/portal_skins/erp5_workflow/WorkflowTool_convertWorkflow.xml
View file @
32ff9e6d
...
...
@@ -86,7 +86,7 @@ for workflow in selected_workflow_list:\n
url_quote(\'workflow(s) is already exist.\')))\n
\n
# conversion and reassignment\n
new_workflow = context.dc_workflow_asERP5Object(
context, workflow, temp=0
)\n
new_workflow = context.dc_workflow_asERP5Object(
workflow, is_temporary=False
)\n
context.reassignWorkflow(new_workflow.getId())\n
selected_workflow_id_list.append(new_workflow.getId())\n
\n
...
...
product/ERP5Type/tests/ERP5TypeTestCase.py
View file @
32ff9e6d
...
...
@@ -1010,14 +1010,14 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
workflow
=
workflow_tool
.
_getOb
(
workflow_id
)
if
workflow
.
getPortalType
()
not
in
[
'Workflow'
,
'Interaction Workflow'
,
'Configuration Workflow'
]:
LOG
(
"### workflow id"
,
0
,
workflow_id
)
new_workflow
=
workflow_tool
.
dc_workflow_asERP5Object
(
workflow
_tool
,
workflow
,
temp
=
0
)
new_workflow
=
workflow_tool
.
dc_workflow_asERP5Object
(
workflow
,
is_temporary
=
False
)
workflow_tool
.
reassignWorkflow
(
workflow_id
)
self
.
commit
()
LOG
(
"### reassigned"
,
0
,
workflow_id
)
# force convert edit_workflow: Why have to load edit_workflow this way?
edit_workflow
=
workflow_tool
.
_getOb
(
'edit_workflow'
,
None
)
if
edit_workflow
is
not
None
:
new_workflow
=
workflow_tool
.
dc_workflow_asERP5Object
(
workflow_tool
,
edit_workflow
,
temp
=
0
)
new_workflow
=
workflow_tool
.
dc_workflow_asERP5Object
(
edit_workflow
,
is_temporary
=
False
)
workflow_tool
.
reassignWorkflow
(
'edit_workflow'
)
LOG
(
"### edit workflow"
,
0
,
"after reassignment"
)
self
.
commit
()
...
...
product/ERP5Workflow/Tool/WorkflowTool.py
View file @
32ff9e6d
...
...
@@ -177,7 +177,8 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
if
wf
.
getPortalType
()
==
'Workflow'
:
# workflow compatibility
action
=
'transition_'
+
action_ref
else
:
action
=
action_ref
else
:
action
=
action_ref
if
wf
.
isActionSupported
(
ob
,
action
,
**
kw
):
found
=
1
break
...
...
@@ -249,42 +250,38 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
workflow_type
=
dc_workflow
.
__class__
.
__name__
if
workflow_type
in
[
'Workflow'
,
'Interaction Workflow'
,
'Configuration Workflow'
]:
continue
temp_workflow
=
self
.
dc_workflow_asERP5Object
(
self
,
dc_workflow
,
temp_obj
)
temp_workflow
=
self
.
dc_workflow_asERP5Object
(
dc_workflow
,
is_temporary
=
temp_obj
)
temp_workflow_list
.
append
(
temp_workflow
)
temp_workflow_id_list
.
append
(
temp_workflow
.
getTitle
())
return
temp_workflow_list
def
dc_workflow_asERP5Object
(
self
,
container
,
dc_workflow
,
temp
):
# convert DC Workflow to New Workflow
def
dc_workflow_asERP5Object
(
self
,
dc_workflow
,
is_temporary
=
False
):
""" convert DC Workflow to New Workflow """
workflow_type_id
=
dc_workflow
.
__class__
.
__name__
if
workflow_type_id
in
[
'DCWorkflowDefinition'
,
'InteractionWorkflowDefinition'
]:
# Only convert old workflow objects.
if
is_temporary
:
new_id
=
dc_workflow
.
id
else
:
new_id
=
'converting_'
+
dc_workflow
.
id
uid
=
self
.
encodeWorkflowUid
(
new_id
)
portal_type
=
(
'Workflow'
if
workflow_type_id
==
'DCWorkflowDefinition'
else
'Interaction Workflow'
)
workflow
=
self
.
newContent
(
id
=
new_id
,
temp_object
=
is_temporary
,
portal_type
=
portal_type
)
if
workflow_type_id
==
'DCWorkflowDefinition'
:
if
temp
==
0
:
new_id
=
'converting_'
+
dc_workflow
.
id
else
:
new_id
=
dc_workflow
.
id
uid
=
self
.
encodeWorkflowUid
(
new_id
)
workflow
=
container
.
newContent
(
id
=
new_id
,
portal_type
=
'Workflow'
,
temp_object
=
temp
)
workflow
.
setStateVariable
(
dc_workflow
.
state_var
)
workflow
.
setWorkflowManagedPermission
(
dc_workflow
.
permissions
)
workflow
.
setManagerBypass
(
dc_workflow
.
manager_bypass
)
elif
workflow_type_id
==
'InteractionWorkflowDefinition'
:
if
temp
==
0
:
new_id
=
'converting_'
+
dc_workflow
.
id
else
:
new_id
=
dc_workflow
.
id
uid
=
self
.
encodeWorkflowUid
(
new_id
)
workflow
=
container
.
newContent
(
id
=
new_id
,
portal_type
=
'Interaction Workflow'
,
temp_object
=
temp
)
if
temp
==
1
:
if
is_temporary
:
# give temp workflow an uid for form_dialog.
workflow
.
uid
=
uid
workflow
.
default_reference
=
dc_workflow
.
id
workflow
.
setTitle
(
dc_workflow
.
title
)
workflow
.
setDescription
(
dc_workflow
.
description
)
if
temp
==
0
:
if
not
is_temporary
:
# create transitions
if
workflow_type_id
==
'DCWorkflowDefinition'
:
# remove default state and variables
...
...
@@ -296,7 +293,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
# create transition (portal_type = Transition)
for
tid
in
dc_workflow_transition_value_list
:
tdef
=
dc_workflow_transition_value_list
.
get
(
tid
)
transition
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
temp_object
=
temp
)
transition
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
temp_object
=
is_temporary
)
if
tdef
.
title
==
''
or
tdef
.
title
is
None
:
tdef
.
title
=
UpperCase
(
tdef
.
id
)
transition
.
setTitle
(
tdef
.
title
)
...
...
@@ -338,7 +335,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
# create states (portal_type = State)
for
sid
in
dc_workflow
.
states
:
sdef
=
dc_workflow
.
states
.
get
(
sid
)
state
=
workflow
.
newContent
(
portal_type
=
'State'
,
temp_object
=
temp
)
state
=
workflow
.
newContent
(
portal_type
=
'State'
,
temp_object
=
is_temporary
)
if
sdef
.
title
==
''
or
sdef
.
title
is
None
:
sdef
.
title
=
UpperCase
(
sdef
.
id
)
if
hasattr
(
sdef
,
'type_list'
):
state
.
setStateType
(
sdef
.
type_list
)
...
...
@@ -382,7 +379,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
# worklists (portal_type = Worklist)
for
qid
in
dc_workflow
.
worklists
:
qdef
=
dc_workflow
.
worklists
.
get
(
qid
)
worklist
=
workflow
.
newContent
(
portal_type
=
'Worklist'
,
temp_object
=
temp
)
worklist
=
workflow
.
newContent
(
portal_type
=
'Worklist'
,
temp_object
=
is_temporary
)
worklist
.
setTitle
(
qdef
.
title
)
worklist
.
setReference
(
qdef
.
id
)
worklist
.
setDescription
(
qdef
.
description
)
...
...
@@ -427,11 +424,11 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
if
qdef
.
guard
.
expr
is
not
None
:
worklist
.
setExpression
(
qdef
.
guard
.
expr
.
text
)
elif
workflow_type_id
==
'InteractionWorkflowDefinition'
:
dc_workflow_interaction_value_
lis
t
=
dc_workflow
.
interactions
dc_workflow_interaction_value_
dic
t
=
dc_workflow
.
interactions
# create interactions (portal_type = Interaction)
for
tid
in
dc_workflow_interaction_value_
lis
t
:
interaction
=
workflow
.
newContent
(
portal_type
=
'Interaction'
,
temp_object
=
temp
)
tdef
=
dc_workflow_interaction_value_
lis
t
.
get
(
tid
)
for
tid
in
dc_workflow_interaction_value_
dic
t
:
interaction
=
workflow
.
newContent
(
portal_type
=
'Interaction'
,
temp_object
=
is_temporary
)
tdef
=
dc_workflow_interaction_value_
dic
t
.
get
(
tid
)
if
tdef
.
title
:
interaction
.
setTitle
(
tdef
.
title
)
interaction
.
setReference
(
tdef
.
id
)
...
...
@@ -488,9 +485,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
script
=
dc_workflow_script_list
.
get
(
script_id
)
# add a prefix if there is a script & method conflict
if
hasattr
(
workflow
,
script_id
):
workflow_script
=
workflow
.
newContent
(
id
=
'ScriptPrefix_'
+
script_id
,
portal_type
=
'Workflow Script'
,
temp_object
=
temp
)
workflow_script
=
workflow
.
newContent
(
id
=
'ScriptPrefix_'
+
script_id
,
portal_type
=
'Workflow Script'
,
temp_object
=
is_temporary
)
else
:
workflow_script
=
workflow
.
newContent
(
id
=
script_id
,
portal_type
=
'Workflow Script'
,
temp_object
=
temp
)
workflow_script
=
workflow
.
newContent
(
id
=
script_id
,
portal_type
=
'Workflow Script'
,
temp_object
=
is_temporary
)
workflow_script
.
setTitle
(
script
.
title
)
workflow_script
.
default_reference
=
script_id
workflow_script
.
setParameterSignature
(
script
.
_params
)
...
...
@@ -498,31 +495,32 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
workflow_script
.
setBody
(
script
.
_body
)
workflow_script
.
setProxyRole
(
script
.
_proxy_roles
)
# create variables (portal_type = Variable)
dc_workflow_variable_list
=
dc_workflow
.
variables
for
vid
in
dc_workflow_variable_list
:
vdef
=
dc_workflow_variable_list
.
get
(
vid
)
variable
=
workflow
.
newContent
(
portal_type
=
'Variable'
,
temp_object
=
temp
)
variable
.
setTitle
(
vdef
.
title
)
variable
.
setReference
(
vdef
.
id
)
variable
.
setAutomaticUpdate
(
vdef
.
update_always
)
if
getattr
(
vdef
,
'default_expr'
,
None
)
is
not
None
:
for
variable_id
,
variable_definition
in
dc_workflow
.
variables
.
items
():
variable
=
workflow
.
newContent
(
portal_type
=
'Variable'
,
temp_object
=
is_temporary
)
variable
.
setTitle
(
variable_definition
.
title
)
variable
.
setReference
(
variable_id
)
variable
.
setAutomaticUpdate
(
variable_definition
.
update_always
)
if
getattr
(
variable_definition
,
'default_expr'
,
None
)
is
not
None
:
# for a very specific case, action return the reference of transition
# in order to generation correct workflow history.
if
vid
==
'action'
:
LOG
(
"### workflow:"
,
INFO
,
workflow
)
LOG
(
"### variable_definition:"
,
INFO
,
variable_definition
)
if
variable_id
==
'action'
:
variable
.
setDefaultExpression
(
'transition/getReference|nothing'
)
else
:
variable
.
setDefaultExpression
(
vdef
.
default_expr
.
text
)
if
vdef
.
info_guard
:
variable
.
info_guard
=
vdef
.
info_guard
variable
.
setRoleList
(
vdef
.
info_guard
.
roles
)
variable
.
setPermissionList
(
vdef
.
info_guard
.
permissions
)
variable
.
setGroupList
(
vdef
.
info_guard
.
groups
)
if
vdef
.
info_guard
.
expr
is
not
None
:
else
:
variable
.
setDefaultExpression
(
variable_definition
.
default_expr
.
text
)
if
variable_definition
.
info_guard
:
variable
.
info_guard
=
variable_definition
.
info_guard
variable
.
setRoleList
(
variable_definition
.
info_guard
.
roles
)
variable
.
setPermissionList
(
variable_definition
.
info_guard
.
permissions
)
variable
.
setGroupList
(
variable_definition
.
info_guard
.
groups
)
if
variable_definition
.
info_guard
.
expr
is
not
None
:
# Here add expression text, convert to expression in getMatchVar.
variable
.
setExpression
(
tdef
.
info_guard
.
expr
.
text
)
variable
.
setForCatalog
(
v
def
.
for_catalog
)
variable
.
setForStatus
(
v
def
.
for_status
)
variable
.
setInitialValue
(
v
def
.
default_value
)
variable
.
setDescription
(
v
def
.
description
)
variable
.
setForCatalog
(
v
ariable_definition
.
for_catalog
)
variable
.
setForStatus
(
v
ariable_definition
.
for_status
)
variable
.
setInitialValue
(
v
ariable_definition
.
default_value
)
variable
.
setDescription
(
v
ariable_definition
.
description
)
# Configure transition variable:
if
getattr
(
dc_workflow
,
'transitions'
,
None
)
is
not
None
:
dc_workflow_transition_value_list
=
dc_workflow
.
transitions
...
...
@@ -534,7 +532,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
var_exprs
=
{}
else
:
var_exprs
=
origin_tdef
.
var_exprs
for
key
in
var_exprs
:
tr_var
=
transition
.
newContent
(
portal_type
=
'Transition Variable'
,
temp_object
=
temp
)
tr_var
=
transition
.
newContent
(
portal_type
=
'Transition Variable'
,
temp_object
=
is_temporary
)
tr_var
.
setDefaultExpression
(
var_exprs
[
key
].
text
)
tr_var_path
=
getattr
(
workflow
,
'variable_'
+
key
).
getPath
()
tr_var_path
=
'/'
.
join
(
tr_var_path
.
split
(
'/'
)[
2
:])
...
...
@@ -551,7 +549,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
var_exprs
=
{}
else
:
var_exprs
=
origin_tdef
.
var_exprs
for
key
in
var_exprs
:
tr_var
=
interaction
.
newContent
(
portal_type
=
'Transition Variable'
,
temp_object
=
temp
)
tr_var
=
interaction
.
newContent
(
portal_type
=
'Transition Variable'
,
temp_object
=
is_temporary
)
tr_var
.
setDefaultExpression
(
var_exprs
[
key
].
text
)
tr_var_path
=
getattr
(
workflow
,
'variable_'
+
key
).
getPath
()
tr_var_path
=
'/'
.
join
(
tr_var_path
.
split
(
'/'
)[
2
:])
...
...
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