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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Binh
erp5
Commits
9b5f7282
Commit
9b5f7282
authored
Mar 06, 2015
by
wenjie.zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Transition.py & Workflow.py: Improve workflow history generation.
parent
bbdcfa3d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
93 deletions
+12
-93
product/ERP5Workflow/Document/Transition.py
product/ERP5Workflow/Document/Transition.py
+5
-90
product/ERP5Workflow/Document/Workflow.py
product/ERP5Workflow/Document/Workflow.py
+7
-3
No files found.
product/ERP5Workflow/Document/Transition.py
View file @
9b5f7282
...
...
@@ -77,7 +77,7 @@ class Transition(XMLObject):
# Get variable values
state_bc_id
=
workflow
.
getStateBaseCategory
()
status_dict
=
workflow
.
getCurrentStatusDict
(
document
)
state_object
=
document
.
unrestrictedTraverse
(
status_dict
[
state_bc_id
])
state_object
=
workflow
.
_getOb
(
status_dict
[
state_bc_id
])
old_state
=
state_object
.
getId
()
new_state
=
document
.
unrestrictedTraverse
(
self
.
getDestination
()).
getId
()
...
...
@@ -135,9 +135,11 @@ class Transition(XMLObject):
self
.
getParent
().
updateRoleMappingsFor
(
document
)
status_dict
[
'undo'
]
=
0
status_dict
[
'action'
]
=
self
.
getId
()
# Modify workflow history
status_dict
[
state_bc_id
]
=
document
.
getCategoryMembershipList
(
state_bc_id
)[
0
]
#status_dict[state_bc_id] = document.getCategoryMembershipList(state_bc_id)[0]
status_dict
[
state_bc_id
]
=
new_state
object
=
workflow
.
getStateChangeInformation
(
document
,
state_object
,
transition
=
self
)
# Update all variables
...
...
@@ -154,6 +156,7 @@ class Transition(XMLObject):
# Update all transition variables
if
form_kw
is
not
None
:
object
.
REQUEST
.
other
.
update
(
form_kw
)
# zwj: The transition variable is replaced by a base category; thus this part is not in use.
for
variable
in
self
.
contentValues
(
portal_type
=
'Transition Variable'
):
status_dict
[
variable
.
getCausalityTitle
()]
=
variable
.
getInitialValue
(
object
=
object
)
...
...
@@ -179,52 +182,6 @@ class Transition(XMLObject):
else
:
return
new_sdef
""" the old execution
if form_kw is None:
form_kw = {}
workflow = self.getParentValue()
# Get variable values
state_bc_id = workflow.getStateBaseCategory()
status_dict = workflow.getCurrentStatusDict(document)
state_object = document.unrestrictedTraverse(status_dict[state_bc_id])
# Call the before script
self._executeBeforeScript(document, workflow, state_object, form_kw=form_kw)
# Modify the state
self._changeState(document)
### zwj: update Role mapping, also in Workflow, initialiseDocument()
self.getParent().updateRoleMappingsFor(document)
status_dict['undo'] = 0
# Modify workflow history
status_dict[state_bc_id] = document.getCategoryMembershipList(state_bc_id)[0]
object = workflow.getStateChangeInformation(document, state_object, transition=self)
# Update all variables
for variable in workflow.contentValues(portal_type='Variable'):
if variable.getAutomaticUpdate():
# if we have it in form get it from there
# otherwise use default
variable_title = variable.getTitle()
if variable_title in form_kw:
status_dict[variable_title] = form_kw[variable_title]
else:
status_dict[variable_title] = variable.getInitialValue(object=object)
# Update all transition variables
if form_kw is not None:
object.REQUEST.other.update(form_kw)
for variable in self.contentValues(portal_type='Transition Variable'):
status_dict[variable.getCausalityTitle()] = variable.getInitialValue(object=object)
workflow._updateWorkflowHistory(document, status_dict)
# Call the after script
self._executeAfterScript(document, workflow, state_object, form_kw=form_kw)
"""
def
_changeState
(
self
,
document
):
"""
Change the state of the object.
...
...
@@ -235,48 +192,6 @@ class Transition(XMLObject):
state_bc_id
=
self
.
getParentValue
().
getStateBaseCategory
()
document
.
setCategoryMembership
(
state_bc_id
,
state
)
def
_executeAfterScript
(
self
,
document
,
workflow
,
state_object
,
form_kw
=
None
):
"""
Execute post transition script.
"""
former_status
=
state_object
.
getId
()
old_sdef
=
state_object
new_sdef
=
document
.
unrestrictedTraverse
(
self
.
getDestination
())
kwargs
=
form_kw
sci
=
StateChangeInfo
(
document
,
workflow
,
former_status
,
self
,
old_sdef
,
new_sdef
,
kwargs
)
if
form_kw
is
None
:
form_kw
=
{}
script_id
=
self
.
getAfterScriptId
()
if
script_id
is
not
None
:
script
=
self
.
getParent
().
_getOb
(
script_id
)
if
script
is
not
None
:
LOG
(
"zwj: Executing after script %s for %s"
%
(
script_id
,
self
.
getId
()),
WARNING
,
"in Transition.py."
)
#script(**form_kw) ### zwj: call the name of script to execute itself
script
.
execute
(
sci
)
def
_executeBeforeScript
(
self
,
document
,
workflow
,
state_object
,
form_kw
=
None
):
"""
Execute pre transition script.
"""
former_status
=
state_object
.
getId
()
old_sdef
=
state_object
new_sdef
=
document
.
unrestrictedTraverse
(
self
.
getDestination
())
kwargs
=
form_kw
sci
=
StateChangeInfo
(
document
,
workflow
,
former_status
,
self
,
old_sdef
,
new_sdef
,
kwargs
)
if
form_kw
is
None
:
form_kw
=
{}
script_id
=
self
.
getBeforeScriptId
()
if
script_id
is
not
None
:
script
=
self
.
getParent
().
_getOb
(
script_id
)
#script = getattr(document, script_id)
#script(**form_kw)
if
script
is
not
None
:
LOG
(
"zwj: Executing before script %s for %s"
%
(
script_id
,
self
.
getId
()),
WARNING
,
"in Transition.py."
)
#script(**form_kw) ### zwj: call the name of script to execute itself
script
.
execute
(
sci
)
def
_checkPermission
(
self
,
document
):
"""
Check if transition is allowed.
...
...
product/ERP5Workflow/Document/Workflow.py
View file @
9b5f7282
...
...
@@ -82,7 +82,9 @@ class Workflow(XMLObject):
object
=
self
.
getStateChangeInformation
(
document
,
self
.
getSourceValue
())
# Initialize workflow history
status_dict
=
{
state_bc_id
:
self
.
getSource
()}
status_dict
=
{
state_bc_id
:
document
.
unrestrictedTraverse
(
self
.
getSource
()).
getId
()}
status_dict
[
'time'
]
=
self
.
getDateTime
()
status_dict
[
'action'
]
=
None
variable_list
=
self
.
contentValues
(
portal_type
=
'Variable'
)
for
variable
in
variable_list
:
status_dict
[
variable
.
getTitle
()]
=
variable
.
getInitialValue
(
object
=
object
)
...
...
@@ -94,7 +96,8 @@ class Workflow(XMLObject):
"""
Generate a key used in the workflow history.
"""
return
self
.
getRelativeUrl
()
history_key
=
self
.
unrestrictedTraverse
(
self
.
getRelativeUrl
()).
getId
()
return
history_key
def
_updateWorkflowHistory
(
self
,
document
,
status_dict
):
"""
...
...
@@ -112,7 +115,8 @@ class Workflow(XMLObject):
document
.
workflow_history
[
workflow_key
]
=
()
# Update history
document
.
workflow_history
[
workflow_key
]
+=
(
status_dict
,
)
status_dict
[
'time'
]
=
self
.
getDateTime
()
document
.
workflow_history
[
workflow_key
]
+=
(
status_dict
,)
# XXX this _p_changed marks the document modified, but the
# only the PersistentMapping is modified
document
.
_p_changed
=
1
...
...
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