Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Products.DCWorkflow
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
Kirill Smelkov
Products.DCWorkflow
Commits
cd29c843
Commit
cd29c843
authored
Apr 24, 2012
by
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code cleanup:
- replaced has_key - replaced oldstyle errors - PEP 8
parent
471e6021
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
586 additions
and
672 deletions
+586
-672
Products/DCWorkflow/ContainerTab.py
Products/DCWorkflow/ContainerTab.py
+8
-8
Products/DCWorkflow/DCWorkflow.py
Products/DCWorkflow/DCWorkflow.py
+20
-16
Products/DCWorkflow/Expression.py
Products/DCWorkflow/Expression.py
+8
-8
Products/DCWorkflow/Guard.py
Products/DCWorkflow/Guard.py
+6
-5
Products/DCWorkflow/Scripts.py
Products/DCWorkflow/Scripts.py
+1
-1
Products/DCWorkflow/States.py
Products/DCWorkflow/States.py
+17
-19
Products/DCWorkflow/Transitions.py
Products/DCWorkflow/Transitions.py
+12
-12
Products/DCWorkflow/WorkflowUIMixin.py
Products/DCWorkflow/WorkflowUIMixin.py
+8
-7
Products/DCWorkflow/Worklists.py
Products/DCWorkflow/Worklists.py
+7
-8
Products/DCWorkflow/exportimport.py
Products/DCWorkflow/exportimport.py
+491
-581
Products/DCWorkflow/utils.py
Products/DCWorkflow/utils.py
+8
-7
No files found.
Products/DCWorkflow/ContainerTab.py
View file @
cd29c843
##############################################################################
##############################################################################
#
#
# Copyright (c) 2001 Zope Foundation and Contributors.
# Copyright (c) 2001 Zope Foundation and Contributors.
#
#
# This software is subject to the provisions of the Zope Public License,
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# FOR A PARTICULAR PURPOSE.
#
#
##############################################################################
##############################################################################
""" A convenient base class for representing a container as a management tab.
""" A convenient base class for representing a container as a management tab.
"""
"""
...
@@ -51,27 +51,27 @@ class ContainerTab(Folder):
...
@@ -51,27 +51,27 @@ class ContainerTab(Folder):
def
_checkId
(
self
,
id
,
allow_dup
=
0
):
def
_checkId
(
self
,
id
,
allow_dup
=
0
):
if
not
allow_dup
:
if
not
allow_dup
:
if
self
.
_mapping
.
has_key
(
id
)
:
if
id
in
self
.
_mapping
:
raise
BadRequest
(
'The id "%s" is already in use.'
%
id
)
raise
BadRequest
(
'The id "%s" is already in use.'
%
id
)
return
Folder
.
_checkId
(
self
,
id
,
allow_dup
)
return
Folder
.
_checkId
(
self
,
id
,
allow_dup
)
def
_getOb
(
self
,
name
,
default
=
_marker
):
def
_getOb
(
self
,
name
,
default
=
_marker
):
mapping
=
self
.
_mapping
mapping
=
self
.
_mapping
if
mapping
.
has_key
(
name
)
:
if
name
in
mapping
:
res
=
mapping
[
name
]
res
=
mapping
[
name
]
if
hasattr
(
res
,
'__of__'
):
if
hasattr
(
res
,
'__of__'
):
res
=
res
.
__of__
(
self
)
res
=
res
.
__of__
(
self
)
return
res
return
res
else
:
else
:
if
default
is
_marker
:
if
default
is
_marker
:
raise
KeyError
,
name
raise
KeyError
(
name
)
return
default
return
default
def
__getattr__
(
self
,
name
):
def
__getattr__
(
self
,
name
):
ob
=
self
.
_mapping
.
get
(
name
,
None
)
ob
=
self
.
_mapping
.
get
(
name
,
None
)
if
ob
is
not
None
:
if
ob
is
not
None
:
return
ob
return
ob
raise
AttributeError
,
name
raise
AttributeError
(
name
)
def
_setOb
(
self
,
name
,
value
):
def
_setOb
(
self
,
name
,
value
):
mapping
=
self
.
_mapping
mapping
=
self
.
_mapping
...
@@ -84,13 +84,13 @@ class ContainerTab(Folder):
...
@@ -84,13 +84,13 @@ class ContainerTab(Folder):
self
.
_mapping
=
mapping
# Trigger persistence.
self
.
_mapping
=
mapping
# Trigger persistence.
def
get
(
self
,
name
,
default
=
None
):
def
get
(
self
,
name
,
default
=
None
):
if
self
.
_mapping
.
has_key
(
name
)
:
if
name
in
self
.
_mapping
:
return
self
[
name
]
return
self
[
name
]
else
:
else
:
return
default
return
default
def
has_key
(
self
,
key
):
def
has_key
(
self
,
key
):
return
self
.
_mapping
.
has_key
(
key
)
return
key
in
self
.
_mapping
def
objectIds
(
self
,
spec
=
None
):
def
objectIds
(
self
,
spec
=
None
):
# spec is not important for now...
# spec is not important for now...
...
...
Products/DCWorkflow/DCWorkflow.py
View file @
cd29c843
...
@@ -45,7 +45,7 @@ from Products.DCWorkflow.WorkflowUIMixin import WorkflowUIMixin
...
@@ -45,7 +45,7 @@ from Products.DCWorkflow.WorkflowUIMixin import WorkflowUIMixin
def
checkId
(
id
):
def
checkId
(
id
):
res
=
bad_id
(
id
)
res
=
bad_id
(
id
)
if
res
!=
-
1
and
res
is
not
None
:
if
res
!=
-
1
and
res
is
not
None
:
raise
ValueError
,
'Illegal ID'
raise
ValueError
(
'Illegal ID'
)
return
1
return
1
...
@@ -88,8 +88,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
...
@@ -88,8 +88,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
{
'label'
:
'Worklists'
,
'action'
:
'worklists/manage_main'
},
{
'label'
:
'Worklists'
,
'action'
:
'worklists/manage_main'
},
{
'label'
:
'Scripts'
,
'action'
:
'scripts/manage_main'
},
{
'label'
:
'Scripts'
,
'action'
:
'scripts/manage_main'
},
{
'label'
:
'Permissions'
,
'action'
:
'manage_permissions'
},
{
'label'
:
'Permissions'
,
'action'
:
'manage_permissions'
},
{
'label'
:
'Groups'
,
'action'
:
'manage_groups'
},
{
'label'
:
'Groups'
,
'action'
:
'manage_groups'
})
)
security
=
ClassSecurityInfo
()
security
=
ClassSecurityInfo
()
security
.
declareObjectProtected
(
ManagePortal
)
security
.
declareObjectProtected
(
ManagePortal
)
...
@@ -155,7 +154,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
...
@@ -155,7 +154,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
status
=
self
.
_getStatusOf
(
ob
)
status
=
self
.
_getStatusOf
(
ob
)
for
id
,
vdef
in
self
.
variables
.
items
():
for
id
,
vdef
in
self
.
variables
.
items
():
if
vdef
.
for_catalog
:
if
vdef
.
for_catalog
:
if
status
.
has_key
(
id
)
:
if
id
in
status
:
value
=
status
[
id
]
value
=
status
[
id
]
# Not set yet. Use a default.
# Not set yet. Use a default.
...
@@ -195,7 +194,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
...
@@ -195,7 +194,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
'name'
:
tdef
.
actbox_name
%
info
,
'name'
:
tdef
.
actbox_name
%
info
,
'url'
:
tdef
.
actbox_url
%
info
,
'url'
:
tdef
.
actbox_url
%
info
,
'icon'
:
tdef
.
actbox_icon
%
info
,
'icon'
:
tdef
.
actbox_icon
%
info
,
'permissions'
:
(),
# Predetermined.
'permissions'
:
(),
# Predetermined.
'category'
:
tdef
.
actbox_category
,
'category'
:
tdef
.
actbox_category
,
'transition'
:
tdef
}))
'transition'
:
tdef
}))
res
.
sort
()
res
.
sort
()
...
@@ -234,7 +233,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
...
@@ -234,7 +233,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
'name'
:
qdef
.
actbox_name
%
fmt_data
,
'name'
:
qdef
.
actbox_name
%
fmt_data
,
'url'
:
qdef
.
actbox_url
%
fmt_data
,
'url'
:
qdef
.
actbox_url
%
fmt_data
,
'icon'
:
qdef
.
actbox_icon
%
fmt_data
,
'icon'
:
qdef
.
actbox_icon
%
fmt_data
,
'permissions'
:
(),
# Predetermined.
'permissions'
:
(),
# Predetermined.
'category'
:
qdef
.
actbox_category
}))
'category'
:
qdef
.
actbox_category
}))
fmt_data
.
_pop
()
fmt_data
.
_pop
()
res
.
sort
()
res
.
sort
()
...
@@ -303,7 +302,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
...
@@ -303,7 +302,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
getSecurityManager
(),
self
,
ob
):
getSecurityManager
(),
self
,
ob
):
return
default
return
default
status
=
self
.
_getStatusOf
(
ob
)
status
=
self
.
_getStatusOf
(
ob
)
if
status
is
not
None
and
status
.
has_key
(
name
)
:
if
status
is
not
None
and
name
in
status
:
value
=
status
[
name
]
value
=
status
[
name
]
# Not set yet. Use a default.
# Not set yet. Use a default.
...
@@ -332,7 +331,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
...
@@ -332,7 +331,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
"""
"""
try
:
try
:
self
.
_changeStateOf
(
ob
,
None
)
self
.
_changeStateOf
(
ob
,
None
)
except
(
ObjectDeleted
,
ObjectMoved
):
except
(
ObjectDeleted
,
ObjectMoved
):
# Swallow.
# Swallow.
pass
pass
...
@@ -459,7 +458,8 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
...
@@ -459,7 +458,8 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
raise
WorkflowException
(
msg
)
raise
WorkflowException
(
msg
)
# Fire "before" event
# Fire "before" event
notify
(
BeforeTransitionEvent
(
ob
,
self
,
old_sdef
,
new_sdef
,
tdef
,
former_status
,
kwargs
))
notify
(
BeforeTransitionEvent
(
ob
,
self
,
old_sdef
,
new_sdef
,
tdef
,
former_status
,
kwargs
))
# Execute the "before" script.
# Execute the "before" script.
if
tdef
is
not
None
and
tdef
.
script_name
:
if
tdef
is
not
None
and
tdef
.
script_name
:
...
@@ -475,20 +475,23 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
...
@@ -475,20 +475,23 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
# Update variables.
# Update variables.
state_values
=
new_sdef
.
var_values
state_values
=
new_sdef
.
var_values
if
state_values
is
None
:
state_values
=
{}
if
state_values
is
None
:
state_values
=
{}
tdef_exprs
=
None
tdef_exprs
=
None
if
tdef
is
not
None
:
tdef_exprs
=
tdef
.
var_exprs
if
tdef
is
not
None
:
if
tdef_exprs
is
None
:
tdef_exprs
=
{}
tdef_exprs
=
tdef
.
var_exprs
if
tdef_exprs
is
None
:
tdef_exprs
=
{}
status
=
{}
status
=
{}
for
id
,
vdef
in
self
.
variables
.
items
():
for
id
,
vdef
in
self
.
variables
.
items
():
if
not
vdef
.
for_status
:
if
not
vdef
.
for_status
:
continue
continue
expr
=
None
expr
=
None
if
state_values
.
has_key
(
id
)
:
if
id
in
state_values
:
value
=
state_values
[
id
]
value
=
state_values
[
id
]
elif
tdef_exprs
.
has_key
(
id
)
:
elif
id
in
tdef_exprs
:
expr
=
tdef_exprs
[
id
]
expr
=
tdef_exprs
[
id
]
elif
not
vdef
.
update_always
and
former_status
.
has_key
(
id
)
:
elif
not
vdef
.
update_always
and
id
in
former_status
:
# Preserve former value
# Preserve former value
value
=
former_status
[
id
]
value
=
former_status
[
id
]
else
:
else
:
...
@@ -525,7 +528,8 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
...
@@ -525,7 +528,8 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
script
(
sci
)
# May throw an exception.
script
(
sci
)
# May throw an exception.
# Fire "after" event
# Fire "after" event
notify
(
AfterTransitionEvent
(
ob
,
self
,
old_sdef
,
new_sdef
,
tdef
,
status
,
kwargs
))
notify
(
AfterTransitionEvent
(
ob
,
self
,
old_sdef
,
new_sdef
,
tdef
,
status
,
kwargs
))
# Return the new state object.
# Return the new state object.
if
moved_exc
is
not
None
:
if
moved_exc
is
not
None
:
...
...
Products/DCWorkflow/Expression.py
View file @
cd29c843
##############################################################################
##############################################################################
#
#
# Copyright (c) 2001 Zope Foundation and Contributors.
# Copyright (c) 2001 Zope Foundation and Contributors.
#
#
# This software is subject to the provisions of the Zope Public License,
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# FOR A PARTICULAR PURPOSE.
#
#
##############################################################################
##############################################################################
""" Expressions in a web-configurable workflow.
""" Expressions in a web-configurable workflow.
"""
"""
...
@@ -19,6 +19,7 @@ from Acquisition import aq_inner
...
@@ -19,6 +19,7 @@ from Acquisition import aq_inner
from
Acquisition
import
aq_parent
from
Acquisition
import
aq_parent
from
App.class_init
import
InitializeClass
from
App.class_init
import
InitializeClass
from
DateTime.DateTime
import
DateTime
from
DateTime.DateTime
import
DateTime
from
MultiMapping
import
MultiMapping
from
Products.PageTemplates.Expressions
import
getEngine
from
Products.PageTemplates.Expressions
import
getEngine
from
Products.PageTemplates.Expressions
import
SecureModuleImporter
from
Products.PageTemplates.Expressions
import
SecureModuleImporter
...
@@ -28,10 +29,8 @@ from Products.CMFCore.WorkflowCore import ObjectDeleted
...
@@ -28,10 +29,8 @@ from Products.CMFCore.WorkflowCore import ObjectDeleted
from
Products.CMFCore.WorkflowCore
import
ObjectMoved
from
Products.CMFCore.WorkflowCore
import
ObjectMoved
# We don't import SafeMapping from Products.PageTemplates.TALES
# because it's deprecated in Zope 2.10
from
MultiMapping
import
MultiMapping
class
SafeMapping
(
MultiMapping
):
class
SafeMapping
(
MultiMapping
):
"""Mapping with security declarations and limited method exposure.
"""Mapping with security declarations and limited method exposure.
Since it subclasses MultiMapping, this class can be used to wrap
Since it subclasses MultiMapping, this class can be used to wrap
...
@@ -45,7 +44,8 @@ class SafeMapping(MultiMapping):
...
@@ -45,7 +44,8 @@ class SafeMapping(MultiMapping):
_pop
=
MultiMapping
.
pop
_pop
=
MultiMapping
.
pop
class
StateChangeInfo
:
class
StateChangeInfo
(
object
):
'''
'''
Provides information for expressions and scripts.
Provides information for expressions and scripts.
'''
'''
...
@@ -83,7 +83,7 @@ class StateChangeInfo:
...
@@ -83,7 +83,7 @@ class StateChangeInfo:
def
__getitem__
(
self
,
name
):
def
__getitem__
(
self
,
name
):
if
name
[:
1
]
!=
'_'
and
hasattr
(
self
,
name
):
if
name
[:
1
]
!=
'_'
and
hasattr
(
self
,
name
):
return
getattr
(
self
,
name
)
return
getattr
(
self
,
name
)
raise
KeyError
,
name
raise
KeyError
(
name
)
def
getHistory
(
self
):
def
getHistory
(
self
):
wf
=
self
.
workflow
wf
=
self
.
workflow
...
@@ -126,7 +126,7 @@ def createExprContext(sci):
...
@@ -126,7 +126,7 @@ def createExprContext(sci):
'folder'
:
container
,
'folder'
:
container
,
'nothing'
:
None
,
'nothing'
:
None
,
'root'
:
ob
.
getPhysicalRoot
(),
'root'
:
ob
.
getPhysicalRoot
(),
'request'
:
getattr
(
ob
,
'REQUEST'
,
None
),
'request'
:
getattr
(
ob
,
'REQUEST'
,
None
),
'modules'
:
SecureModuleImporter
,
'modules'
:
SecureModuleImporter
,
'user'
:
getSecurityManager
().
getUser
(),
'user'
:
getSecurityManager
().
getUser
(),
'state_change'
:
sci
,
'state_change'
:
sci
,
...
...
Products/DCWorkflow/Guard.py
View file @
cd29c843
...
@@ -30,7 +30,8 @@ from Products.DCWorkflow.permissions import ManagePortal
...
@@ -30,7 +30,8 @@ from Products.DCWorkflow.permissions import ManagePortal
from
Products.DCWorkflow.utils
import
_dtmldir
from
Products.DCWorkflow.utils
import
_dtmldir
class
Guard
(
Persistent
,
Explicit
):
class
Guard
(
Persistent
,
Explicit
):
permissions
=
()
permissions
=
()
roles
=
()
roles
=
()
groups
=
()
groups
=
()
...
@@ -68,10 +69,10 @@ class Guard (Persistent, Explicit):
...
@@ -68,10 +69,10 @@ class Guard (Persistent, Explicit):
if
self
.
groups
:
if
self
.
groups
:
# Require at least one of the specified groups.
# Require at least one of the specified groups.
u
=
sm
.
getUser
()
u
=
sm
.
getUser
()
b
=
aq_base
(
u
)
b
=
aq_base
(
u
)
if
hasattr
(
b
,
'getGroupsInContext'
):
if
hasattr
(
b
,
'getGroupsInContext'
):
u_groups
=
u
.
getGroupsInContext
(
ob
)
u_groups
=
u
.
getGroupsInContext
(
ob
)
elif
hasattr
(
b
,
'getGroups'
):
elif
hasattr
(
b
,
'getGroups'
):
u_groups
=
u
.
getGroups
()
u_groups
=
u
.
getGroups
()
else
:
else
:
u_groups
=
()
u_groups
=
()
...
...
Products/DCWorkflow/Scripts.py
View file @
cd29c843
...
@@ -21,7 +21,7 @@ from Products.DCWorkflow.ContainerTab import ContainerTab
...
@@ -21,7 +21,7 @@ from Products.DCWorkflow.ContainerTab import ContainerTab
from
Products.DCWorkflow.permissions
import
ManagePortal
from
Products.DCWorkflow.permissions
import
ManagePortal
class
Scripts
(
ContainerTab
):
class
Scripts
(
ContainerTab
):
"""A container for workflow scripts"""
"""A container for workflow scripts"""
meta_type
=
'Workflow Scripts'
meta_type
=
'Workflow Scripts'
...
...
Products/DCWorkflow/States.py
View file @
cd29c843
...
@@ -29,6 +29,7 @@ from Products.DCWorkflow.utils import _dtmldir
...
@@ -29,6 +29,7 @@ from Products.DCWorkflow.utils import _dtmldir
class
StateDefinition
(
SimpleItem
):
class
StateDefinition
(
SimpleItem
):
"""State definition"""
"""State definition"""
meta_type
=
'Workflow State'
meta_type
=
'Workflow State'
...
@@ -37,8 +38,7 @@ class StateDefinition(SimpleItem):
...
@@ -37,8 +38,7 @@ class StateDefinition(SimpleItem):
{
'label'
:
'Properties'
,
'action'
:
'manage_properties'
},
{
'label'
:
'Properties'
,
'action'
:
'manage_properties'
},
{
'label'
:
'Permissions'
,
'action'
:
'manage_permissions'
},
{
'label'
:
'Permissions'
,
'action'
:
'manage_permissions'
},
{
'label'
:
'Groups'
,
'action'
:
'manage_groups'
},
{
'label'
:
'Groups'
,
'action'
:
'manage_groups'
},
{
'label'
:
'Variables'
,
'action'
:
'manage_variables'
},
{
'label'
:
'Variables'
,
'action'
:
'manage_variables'
})
)
title
=
''
title
=
''
description
=
''
description
=
''
...
@@ -60,8 +60,8 @@ class StateDefinition(SimpleItem):
...
@@ -60,8 +60,8 @@ class StateDefinition(SimpleItem):
return
aq_parent
(
aq_inner
(
aq_parent
(
aq_inner
(
self
))))
return
aq_parent
(
aq_inner
(
aq_parent
(
aq_inner
(
self
))))
def
getTransitions
(
self
):
def
getTransitions
(
self
):
return
filter
(
self
.
getWorkflow
().
transitions
.
has_key
,
return
[
t
for
t
in
self
.
transitions
self
.
transitions
)
if
t
in
self
.
getWorkflow
().
transitions
]
def
getTransitionTitle
(
self
,
tid
):
def
getTransitionTitle
(
self
,
tid
):
t
=
self
.
getWorkflow
().
transitions
.
get
(
tid
,
None
)
t
=
self
.
getWorkflow
().
transitions
.
get
(
tid
,
None
)
...
@@ -88,13 +88,13 @@ class StateDefinition(SimpleItem):
...
@@ -88,13 +88,13 @@ class StateDefinition(SimpleItem):
if
self
.
permission_roles
:
if
self
.
permission_roles
:
roles
=
self
.
permission_roles
.
get
(
p
,
None
)
roles
=
self
.
permission_roles
.
get
(
p
,
None
)
if
roles
is
None
:
if
roles
is
None
:
return
{
'acquired'
:
1
,
'roles'
:
[]}
return
{
'acquired'
:
1
,
'roles'
:
[]}
else
:
else
:
if
isinstance
(
roles
,
tuple
):
if
isinstance
(
roles
,
tuple
):
acq
=
0
acq
=
0
else
:
else
:
acq
=
1
acq
=
1
return
{
'acquired'
:
acq
,
'roles'
:
list
(
roles
)}
return
{
'acquired'
:
acq
,
'roles'
:
list
(
roles
)}
def
getGroupInfo
(
self
,
group
):
def
getGroupInfo
(
self
,
group
):
"""Returns the list of roles to be assigned to a group.
"""Returns the list of roles to be assigned to a group.
...
@@ -112,7 +112,8 @@ class StateDefinition(SimpleItem):
...
@@ -112,7 +112,8 @@ class StateDefinition(SimpleItem):
manage_tabs_message
=
manage_tabs_message
,
manage_tabs_message
=
manage_tabs_message
,
)
)
def
setProperties
(
self
,
title
=
''
,
transitions
=
(),
REQUEST
=
None
,
description
=
''
):
def
setProperties
(
self
,
title
=
''
,
transitions
=
(),
REQUEST
=
None
,
description
=
''
):
"""Set the properties for this State."""
"""Set the properties for this State."""
self
.
title
=
str
(
title
)
self
.
title
=
str
(
title
)
self
.
description
=
str
(
description
)
self
.
description
=
str
(
description
)
...
@@ -120,7 +121,6 @@ class StateDefinition(SimpleItem):
...
@@ -120,7 +121,6 @@ class StateDefinition(SimpleItem):
if
REQUEST
is
not
None
:
if
REQUEST
is
not
None
:
return
self
.
manage_properties
(
REQUEST
,
'Properties changed.'
)
return
self
.
manage_properties
(
REQUEST
,
'Properties changed.'
)
_variables_form
=
DTMLFile
(
'state_variables'
,
_dtmldir
)
_variables_form
=
DTMLFile
(
'state_variables'
,
_dtmldir
)
def
manage_variables
(
self
,
REQUEST
,
manage_tabs_message
=
None
):
def
manage_variables
(
self
,
REQUEST
,
manage_tabs_message
=
None
):
...
@@ -147,11 +147,11 @@ class StateDefinition(SimpleItem):
...
@@ -147,11 +147,11 @@ class StateDefinition(SimpleItem):
return
wf_vars
return
wf_vars
ret
=
[]
ret
=
[]
for
vid
in
wf_vars
:
for
vid
in
wf_vars
:
if
not
self
.
var_values
.
has_key
(
vid
)
:
if
not
vid
in
self
.
var_values
:
ret
.
append
(
vid
)
ret
.
append
(
vid
)
return
ret
return
ret
def
addVariable
(
self
,
id
,
value
,
REQUEST
=
None
):
def
addVariable
(
self
,
id
,
value
,
REQUEST
=
None
):
"""Add a WorkflowVariable to State."""
"""Add a WorkflowVariable to State."""
if
self
.
var_values
is
None
:
if
self
.
var_values
is
None
:
self
.
var_values
=
PersistentMapping
()
self
.
var_values
=
PersistentMapping
()
...
@@ -161,11 +161,11 @@ class StateDefinition(SimpleItem):
...
@@ -161,11 +161,11 @@ class StateDefinition(SimpleItem):
if
REQUEST
is
not
None
:
if
REQUEST
is
not
None
:
return
self
.
manage_variables
(
REQUEST
,
'Variable added.'
)
return
self
.
manage_variables
(
REQUEST
,
'Variable added.'
)
def
deleteVariables
(
self
,
ids
=
[],
REQUEST
=
None
):
def
deleteVariables
(
self
,
ids
=
[],
REQUEST
=
None
):
"""Delete a WorkflowVariable from State."""
"""Delete a WorkflowVariable from State."""
vv
=
self
.
var_values
vv
=
self
.
var_values
for
id
in
ids
:
for
id
in
ids
:
if
vv
.
has_key
(
id
)
:
if
id
in
vv
:
del
vv
[
id
]
del
vv
[
id
]
if
REQUEST
is
not
None
:
if
REQUEST
is
not
None
:
...
@@ -184,8 +184,6 @@ class StateDefinition(SimpleItem):
...
@@ -184,8 +184,6 @@ class StateDefinition(SimpleItem):
vv
[
id
]
=
str
(
REQUEST
[
fname
])
vv
[
id
]
=
str
(
REQUEST
[
fname
])
return
self
.
manage_variables
(
REQUEST
,
'Variables changed.'
)
return
self
.
manage_variables
(
REQUEST
,
'Variables changed.'
)
_permissions_form
=
DTMLFile
(
'state_permissions'
,
_dtmldir
)
_permissions_form
=
DTMLFile
(
'state_permissions'
,
_dtmldir
)
def
manage_permissions
(
self
,
REQUEST
,
manage_tabs_message
=
None
):
def
manage_permissions
(
self
,
REQUEST
,
manage_tabs_message
=
None
):
...
@@ -254,6 +252,7 @@ InitializeClass(StateDefinition)
...
@@ -254,6 +252,7 @@ InitializeClass(StateDefinition)
class
States
(
ContainerTab
):
class
States
(
ContainerTab
):
"""A container for state definitions"""
"""A container for state definitions"""
meta_type
=
'Workflow States'
meta_type
=
'Workflow States'
...
@@ -261,10 +260,9 @@ class States(ContainerTab):
...
@@ -261,10 +260,9 @@ class States(ContainerTab):
security
=
ClassSecurityInfo
()
security
=
ClassSecurityInfo
()
security
.
declareObjectProtected
(
ManagePortal
)
security
.
declareObjectProtected
(
ManagePortal
)
all_meta_types
=
({
'name'
:
StateDefinition
.
meta_type
,
all_meta_types
=
({
'name'
:
StateDefinition
.
meta_type
,
'action'
:
'addState'
,
'action'
:
'addState'
,
'permission'
:
ManagePortal
,
'permission'
:
ManagePortal
},)
},)
_manage_states
=
DTMLFile
(
'states'
,
_dtmldir
)
_manage_states
=
DTMLFile
(
'states'
,
_dtmldir
)
...
@@ -297,7 +295,7 @@ class States(ContainerTab):
...
@@ -297,7 +295,7 @@ class States(ContainerTab):
'''
'''
if
not
id
:
if
not
id
:
if
len
(
ids
)
!=
1
:
if
len
(
ids
)
!=
1
:
raise
ValueError
,
'One and only one state must be selected'
raise
ValueError
(
'One and only one state must be selected'
)
id
=
ids
[
0
]
id
=
ids
[
0
]
id
=
str
(
id
)
id
=
str
(
id
)
aq_parent
(
aq_inner
(
self
)).
initial_state
=
id
aq_parent
(
aq_inner
(
self
)).
initial_state
=
id
...
...
Products/DCWorkflow/Transitions.py
View file @
cd29c843
...
@@ -31,7 +31,8 @@ TRIGGER_AUTOMATIC = 0
...
@@ -31,7 +31,8 @@ TRIGGER_AUTOMATIC = 0
TRIGGER_USER_ACTION
=
1
TRIGGER_USER_ACTION
=
1
class
TransitionDefinition
(
SimpleItem
):
class
TransitionDefinition
(
SimpleItem
):
"""Transition definition"""
"""Transition definition"""
meta_type
=
'Workflow Transition'
meta_type
=
'Workflow Transition'
...
@@ -54,8 +55,7 @@ class TransitionDefinition (SimpleItem):
...
@@ -54,8 +55,7 @@ class TransitionDefinition (SimpleItem):
manage_options
=
(
manage_options
=
(
{
'label'
:
'Properties'
,
'action'
:
'manage_properties'
},
{
'label'
:
'Properties'
,
'action'
:
'manage_properties'
},
{
'label'
:
'Variables'
,
'action'
:
'manage_variables'
},
{
'label'
:
'Variables'
,
'action'
:
'manage_variables'
})
)
def
__init__
(
self
,
id
):
def
__init__
(
self
,
id
):
self
.
id
=
id
self
.
id
=
id
...
@@ -152,7 +152,7 @@ class TransitionDefinition (SimpleItem):
...
@@ -152,7 +152,7 @@ class TransitionDefinition (SimpleItem):
else
:
else
:
ret
=
[]
ret
=
[]
for
key
in
ve
.
keys
():
for
key
in
ve
.
keys
():
ret
.
append
((
key
,
self
.
getVarExprText
(
key
)))
ret
.
append
((
key
,
self
.
getVarExprText
(
key
)))
return
ret
return
ret
def
getWorkflowVariables
(
self
):
def
getWorkflowVariables
(
self
):
...
@@ -164,7 +164,7 @@ class TransitionDefinition (SimpleItem):
...
@@ -164,7 +164,7 @@ class TransitionDefinition (SimpleItem):
return
wf_vars
return
wf_vars
ret
=
[]
ret
=
[]
for
vid
in
wf_vars
:
for
vid
in
wf_vars
:
if
not
self
.
var_exprs
.
has_key
(
vid
)
:
if
not
vid
in
self
.
var_exprs
:
ret
.
append
(
vid
)
ret
.
append
(
vid
)
return
ret
return
ret
...
@@ -183,12 +183,12 @@ class TransitionDefinition (SimpleItem):
...
@@ -183,12 +183,12 @@ class TransitionDefinition (SimpleItem):
if
REQUEST
is
not
None
:
if
REQUEST
is
not
None
:
return
self
.
manage_variables
(
REQUEST
,
'Variable added.'
)
return
self
.
manage_variables
(
REQUEST
,
'Variable added.'
)
def
deleteVariables
(
self
,
ids
=
[],
REQUEST
=
None
):
def
deleteVariables
(
self
,
ids
=
[],
REQUEST
=
None
):
''' delete a WorkflowVariable from State
''' delete a WorkflowVariable from State
'''
'''
ve
=
self
.
var_exprs
ve
=
self
.
var_exprs
for
id
in
ids
:
for
id
in
ids
:
if
ve
.
has_key
(
id
)
:
if
id
in
ve
:
del
ve
[
id
]
del
ve
[
id
]
if
REQUEST
is
not
None
:
if
REQUEST
is
not
None
:
...
@@ -217,7 +217,8 @@ class TransitionDefinition (SimpleItem):
...
@@ -217,7 +217,8 @@ class TransitionDefinition (SimpleItem):
InitializeClass
(
TransitionDefinition
)
InitializeClass
(
TransitionDefinition
)
class
Transitions
(
ContainerTab
):
class
Transitions
(
ContainerTab
):
"""A container for transition definitions"""
"""A container for transition definitions"""
meta_type
=
'Workflow Transitions'
meta_type
=
'Workflow Transitions'
...
@@ -225,10 +226,9 @@ class Transitions (ContainerTab):
...
@@ -225,10 +226,9 @@ class Transitions (ContainerTab):
security
=
ClassSecurityInfo
()
security
=
ClassSecurityInfo
()
security
.
declareObjectProtected
(
ManagePortal
)
security
.
declareObjectProtected
(
ManagePortal
)
all_meta_types
=
({
'name'
:
TransitionDefinition
.
meta_type
,
all_meta_types
=
({
'name'
:
TransitionDefinition
.
meta_type
,
'action'
:
'addTransition'
,
'action'
:
'addTransition'
,
'permission'
:
ManagePortal
,
'permission'
:
ManagePortal
},)
},)
_manage_transitions
=
DTMLFile
(
'transitions'
,
_dtmldir
)
_manage_transitions
=
DTMLFile
(
'transitions'
,
_dtmldir
)
...
...
Products/DCWorkflow/WorkflowUIMixin.py
View file @
cd29c843
##############################################################################
##############################################################################
#
#
# Copyright (c) 2001 Zope Foundation and Contributors.
# Copyright (c) 2001 Zope Foundation and Contributors.
#
#
# This software is subject to the provisions of the Zope Public License,
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# FOR A PARTICULAR PURPOSE.
#
#
##############################################################################
##############################################################################
""" Web-configurable workflow UI.
""" Web-configurable workflow UI.
"""
"""
...
@@ -27,7 +27,8 @@ from Products.DCWorkflow.Guard import Guard
...
@@ -27,7 +27,8 @@ from Products.DCWorkflow.Guard import Guard
from
Products.DCWorkflow.utils
import
_dtmldir
from
Products.DCWorkflow.utils
import
_dtmldir
class
WorkflowUIMixin
:
class
WorkflowUIMixin
(
object
):
'''
'''
'''
'''
...
@@ -39,7 +40,7 @@ class WorkflowUIMixin:
...
@@ -39,7 +40,7 @@ class WorkflowUIMixin:
security
.
declareProtected
(
ManagePortal
,
'setProperties'
)
security
.
declareProtected
(
ManagePortal
,
'setProperties'
)
@
postonly
@
postonly
def
setProperties
(
self
,
title
,
manager_bypass
=
0
,
props
=
None
,
def
setProperties
(
self
,
title
,
manager_bypass
=
0
,
props
=
None
,
REQUEST
=
None
,
description
=
''
):
REQUEST
=
None
,
description
=
''
):
"""Sets basic properties.
"""Sets basic properties.
"""
"""
...
@@ -72,9 +73,9 @@ class WorkflowUIMixin:
...
@@ -72,9 +73,9 @@ class WorkflowUIMixin:
"""Adds to the list of permissions to manage.
"""Adds to the list of permissions to manage.
"""
"""
if
p
in
self
.
permissions
:
if
p
in
self
.
permissions
:
raise
ValueError
,
'Already a managed permission: '
+
p
raise
ValueError
(
'Already a managed permission: '
+
p
)
if
REQUEST
is
not
None
and
p
not
in
self
.
getPossiblePermissions
():
if
REQUEST
is
not
None
and
p
not
in
self
.
getPossiblePermissions
():
raise
ValueError
,
'Not a valid permission name:'
+
p
raise
ValueError
(
'Not a valid permission name:'
+
p
)
self
.
permissions
=
self
.
permissions
+
(
p
,)
self
.
permissions
=
self
.
permissions
+
(
p
,)
if
REQUEST
is
not
None
:
if
REQUEST
is
not
None
:
return
self
.
manage_permissions
(
return
self
.
manage_permissions
(
...
@@ -111,7 +112,7 @@ class WorkflowUIMixin:
...
@@ -111,7 +112,7 @@ class WorkflowUIMixin:
def
getAvailableGroups
(
self
):
def
getAvailableGroups
(
self
):
"""Returns a list of available group names.
"""Returns a list of available group names.
"""
"""
gf
=
aq_get
(
self
,
'__allow_groups__'
,
None
,
1
)
gf
=
aq_get
(
self
,
'__allow_groups__'
,
None
,
1
)
if
gf
is
None
:
if
gf
is
None
:
return
()
return
()
try
:
try
:
...
...
Products/DCWorkflow/Worklists.py
View file @
cd29c843
...
@@ -37,6 +37,7 @@ tales_re = re.compile(r'(\w+:)?(.*)')
...
@@ -37,6 +37,7 @@ tales_re = re.compile(r'(\w+:)?(.*)')
class WorklistDefinition(SimpleItem):
class WorklistDefinition(SimpleItem):
"""Worklist definiton"""
"""Worklist definiton"""
meta_type = '
Worklist
'
meta_type = '
Worklist
'
...
@@ -52,9 +53,7 @@ class WorklistDefinition(SimpleItem):
...
@@ -52,9 +53,7 @@ class WorklistDefinition(SimpleItem):
actbox_category = '
global
'
actbox_category = '
global
'
guard = None
guard = None
manage_options = (
manage_options = ({'
label
': '
Properties
', '
action
': '
manage_properties
'},)
{'
label
': '
Properties
', '
action
': '
manage_properties
'},
)
def __init__(self, id):
def __init__(self, id):
self.id = id
self.id = id
...
@@ -141,7 +140,7 @@ class WorklistDefinition(SimpleItem):
...
@@ -141,7 +140,7 @@ class WorklistDefinition(SimpleItem):
self.var_matches[key] = tuple(v)
self.var_matches[key] = tuple(v)
else:
else:
if self.var_matches and
self.var_matches.has_key(key)
:
if self.var_matches and
key in self.var_matches
:
del self.var_matches[key]
del self.var_matches[key]
self.actbox_name = str(actbox_name)
self.actbox_name = str(actbox_name)
self.actbox_url = str(actbox_url)
self.actbox_url = str(actbox_url)
...
@@ -189,6 +188,7 @@ InitializeClass(WorklistDefinition)
...
@@ -189,6 +188,7 @@ InitializeClass(WorklistDefinition)
class Worklists(ContainerTab):
class Worklists(ContainerTab):
"""A container for worklist definitions"""
"""A container for worklist definitions"""
meta_type = '
Worklists
'
meta_type = '
Worklists
'
...
@@ -196,10 +196,9 @@ class Worklists(ContainerTab):
...
@@ -196,10 +196,9 @@ class Worklists(ContainerTab):
security = ClassSecurityInfo()
security = ClassSecurityInfo()
security.declareObjectProtected(ManagePortal)
security.declareObjectProtected(ManagePortal)
all_meta_types = ({'
name
':WorklistDefinition.meta_type,
all_meta_types = ({'
name
': WorklistDefinition.meta_type,
'
action
':'
addWorklist
',
'
action
': '
addWorklist
',
'
permission
': ManagePortal,
'
permission
': ManagePortal},)
},)
_manage_worklists = DTMLFile('
worklists
', _dtmldir)
_manage_worklists = DTMLFile('
worklists
', _dtmldir)
...
...
Products/DCWorkflow/exportimport.py
View file @
cd29c843
...
@@ -32,7 +32,7 @@ from Products.DCWorkflow.utils import _xmldir
...
@@ -32,7 +32,7 @@ from Products.DCWorkflow.utils import _xmldir
from
Products.GenericSetup.interfaces
import
ISetupEnviron
from
Products.GenericSetup.interfaces
import
ISetupEnviron
from
Products.GenericSetup.utils
import
BodyAdapterBase
from
Products.GenericSetup.utils
import
BodyAdapterBase
TRIGGER_TYPES
=
(
'AUTOMATIC'
,
'USER'
)
TRIGGER_TYPES
=
(
'AUTOMATIC'
,
'USER'
)
_FILENAME
=
'workflows.xml'
_FILENAME
=
'workflows.xml'
...
@@ -55,36 +55,35 @@ class DCWorkflowDefinitionBodyAdapter(BodyAdapterBase):
...
@@ -55,36 +55,35 @@ class DCWorkflowDefinitionBodyAdapter(BodyAdapterBase):
encoding
=
'utf-8'
encoding
=
'utf-8'
wfdc
=
WorkflowDefinitionConfigurator
(
self
.
context
)
wfdc
=
WorkflowDefinitionConfigurator
(
self
.
context
)
(
workflow_id
(
_workflow_id
,
,
title
title
,
,
state_variable
state_variable
,
,
initial_state
initial_state
,
,
states
states
,
,
transitions
transitions
,
,
variables
variables
,
,
worklists
worklists
,
,
permissions
permissions
,
,
scripts
scripts
,
,
description
description
,
,
manager_bypass
manager_bypass
,
,
creation_guard
creation_guard
)
=
wfdc
.
parseWorkflowXML
(
body
,
encoding
)
)
=
wfdc
.
parseWorkflowXML
(
body
,
encoding
)
_initDCWorkflow
(
self
.
context
_initDCWorkflow
(
self
.
context
,
,
title
title
,
,
description
description
,
,
manager_bypass
manager_bypass
,
,
creation_guard
creation_guard
,
,
state_variable
state_variable
,
,
initial_state
initial_state
,
,
states
states
,
,
transitions
transitions
,
,
variables
variables
,
,
worklists
worklists
,
,
permissions
permissions
,
,
scripts
scripts
,
,
self
.
environ
self
.
environ
)
)
body
=
property
(
_exportBody
,
_importBody
)
body
=
property
(
_exportBody
,
_importBody
)
...
@@ -93,7 +92,7 @@ class DCWorkflowDefinitionBodyAdapter(BodyAdapterBase):
...
@@ -93,7 +92,7 @@ class DCWorkflowDefinitionBodyAdapter(BodyAdapterBase):
suffix
=
'/definition.xml'
suffix
=
'/definition.xml'
class
WorkflowDefinitionConfigurator
(
Implicit
):
class
WorkflowDefinitionConfigurator
(
Implicit
):
""" Synthesize XML description of site's workflows.
""" Synthesize XML description of site's workflows.
"""
"""
security
=
ClassSecurityInfo
()
security
=
ClassSecurityInfo
()
...
@@ -101,9 +100,8 @@ class WorkflowDefinitionConfigurator( Implicit ):
...
@@ -101,9 +100,8 @@ class WorkflowDefinitionConfigurator( Implicit ):
def
__init__
(
self
,
obj
):
def
__init__
(
self
,
obj
):
self
.
_obj
=
obj
self
.
_obj
=
obj
security
.
declareProtected
(
ManagePortal
,
'getWorkflowInfo'
)
security
.
declareProtected
(
ManagePortal
,
'getWorkflowInfo'
)
def
getWorkflowInfo
(
self
,
workflow_id
):
def
getWorkflowInfo
(
self
,
workflow_id
):
""" Return a mapping describing a given workflow.
""" Return a mapping describing a given workflow.
o Keys in the mappings:
o Keys in the mappings:
...
@@ -122,81 +120,78 @@ class WorkflowDefinitionConfigurator( Implicit ):
...
@@ -122,81 +120,78 @@ class WorkflowDefinitionConfigurator( Implicit ):
"""
"""
workflow
=
self
.
_obj
workflow
=
self
.
_obj
workflow_info
=
{
'id'
:
workflow_id
workflow_info
=
{
'id'
:
workflow_id
,
,
'meta_type'
:
workflow
.
meta_type
'meta_type'
:
workflow
.
meta_type
,
,
'title'
:
workflow
.
title_or_id
()
'title'
:
workflow
.
title_or_id
(),
,
'description'
:
workflow
.
description
'description'
:
workflow
.
description
}
}
if
workflow
.
meta_type
==
DCWorkflowDefinition
.
meta_type
:
if
workflow
.
meta_type
==
DCWorkflowDefinition
.
meta_type
:
self
.
_extractDCWorkflowInfo
(
workflow
,
workflow_info
)
self
.
_extractDCWorkflowInfo
(
workflow
,
workflow_info
)
return
workflow_info
return
workflow_info
security
.
declareProtected
(
ManagePortal
,
'generateWorkflowXML'
)
security
.
declareProtected
(
ManagePortal
,
'generateWorkflowXML'
)
def
generateWorkflowXML
(
self
):
def
generateWorkflowXML
(
self
):
""" Pseudo API.
""" Pseudo API.
"""
"""
return
self
.
_workflowConfig
(
workflow_id
=
self
.
_obj
.
getId
())
\
return
self
.
_workflowConfig
(
workflow_id
=
self
.
_obj
.
getId
())
\
.
encode
(
'utf-8'
)
.
encode
(
'utf-8'
)
security
.
declareProtected
(
ManagePortal
,
'getWorkflowScripts'
)
security
.
declareProtected
(
ManagePortal
,
'getWorkflowScripts'
)
def
getWorkflowScripts
(
self
):
def
getWorkflowScripts
(
self
):
""" Get workflow scripts information
""" Get workflow scripts information
"""
"""
return
self
.
_extractScripts
(
self
.
_obj
)
return
self
.
_extractScripts
(
self
.
_obj
)
security
.
declareProtected
(
ManagePortal
,
'parseWorkflowXML'
)
security
.
declareProtected
(
ManagePortal
,
'parseWorkflowXML'
)
def
parseWorkflowXML
(
self
,
xml
,
encoding
=
'utf-8'
):
def
parseWorkflowXML
(
self
,
xml
,
encoding
=
'utf-8'
):
""" Pseudo API.
""" Pseudo API.
"""
"""
dom
=
parseString
(
xml
)
dom
=
parseString
(
xml
)
root
=
dom
.
getElementsByTagName
(
'dc-workflow'
)[
0
]
root
=
dom
.
getElementsByTagName
(
'dc-workflow'
)[
0
]
workflow_id
=
_getNodeAttribute
(
root
,
'workflow_id'
,
encoding
)
workflow_id
=
_getNodeAttribute
(
root
,
'workflow_id'
,
encoding
)
title
=
_getNodeAttribute
(
root
,
'title'
,
encoding
)
title
=
_getNodeAttribute
(
root
,
'title'
,
encoding
)
try
:
try
:
description
=
_getNodeAttribute
(
root
,
'description'
,
encoding
)
description
=
_getNodeAttribute
(
root
,
'description'
,
encoding
)
except
ValueError
:
except
ValueError
:
# Don't fail on export files that do not have the description field!
# Don't fail on export files that do not have the description
# field!
description
=
''
description
=
''
manager_bypass
=
_queryNodeAttributeBoolean
(
root
,
'manager_bypass'
,
False
)
manager_bypass
=
_queryNodeAttributeBoolean
(
root
,
'manager_bypass'
,
False
)
creation_guard
=
_extractCreationGuard
(
root
,
encoding
)
creation_guard
=
_extractCreationGuard
(
root
,
encoding
)
state_variable
=
_getNodeAttribute
(
root
,
'state_variable'
,
encoding
)
state_variable
=
_getNodeAttribute
(
root
,
'state_variable'
,
encoding
)
initial_state
=
_getNodeAttribute
(
root
,
'initial_state'
,
encoding
)
initial_state
=
_getNodeAttribute
(
root
,
'initial_state'
,
encoding
)
states
=
_extractStateNodes
(
root
,
encoding
)
states
=
_extractStateNodes
(
root
,
encoding
)
transitions
=
_extractTransitionNodes
(
root
,
encoding
)
transitions
=
_extractTransitionNodes
(
root
,
encoding
)
variables
=
_extractVariableNodes
(
root
,
encoding
)
variables
=
_extractVariableNodes
(
root
,
encoding
)
worklists
=
_extractWorklistNodes
(
root
,
encoding
)
worklists
=
_extractWorklistNodes
(
root
,
encoding
)
permissions
=
_extractPermissionNodes
(
root
,
encoding
)
permissions
=
_extractPermissionNodes
(
root
,
encoding
)
scripts
=
_extractScriptNodes
(
root
,
encoding
)
scripts
=
_extractScriptNodes
(
root
,
encoding
)
return
(
workflow_id
return
(
workflow_id
,
,
title
title
,
,
state_variable
state_variable
,
,
initial_state
initial_state
,
,
states
states
,
,
transitions
transitions
,
,
variables
variables
,
,
worklists
worklists
,
,
permissions
permissions
,
,
scripts
scripts
,
,
description
description
,
,
manager_bypass
manager_bypass
,
,
creation_guard
creation_guard
)
)
security
.
declarePrivate
(
'_workflowConfig'
)
security
.
declarePrivate
(
'_workflowConfig'
)
_workflowConfig
=
PageTemplateFile
(
'wtcWorkflowExport.xml'
,
_xmldir
,
_workflowConfig
=
PageTemplateFile
(
'wtcWorkflowExport.xml'
__name__
=
'workflowConfig'
)
,
_xmldir
,
__name__
=
'workflowConfig'
security
.
declarePrivate
(
'_extractDCWorkflowInfo'
)
)
def
_extractDCWorkflowInfo
(
self
,
workflow
,
workflow_info
):
security
.
declarePrivate
(
'_extractDCWorkflowInfo'
)
def
_extractDCWorkflowInfo
(
self
,
workflow
,
workflow_info
):
""" Append the information for a 'workflow' into 'workflow_info'
""" Append the information for a 'workflow' into 'workflow_info'
o 'workflow' must be a DCWorkflowDefinition instance.
o 'workflow' must be a DCWorkflowDefinition instance.
...
@@ -209,7 +204,7 @@ class WorkflowDefinitionConfigurator( Implicit ):
...
@@ -209,7 +204,7 @@ class WorkflowDefinitionConfigurator( Implicit ):
'permissions' -- a list of names of permissions managed
'permissions' -- a list of names of permissions managed
by the workflow
by the workflow
'state_variable' -- the name of the workflow's "main"
'state_variable' -- the name of the workflow's "main"
state variable
state variable
...
@@ -231,17 +226,16 @@ class WorkflowDefinitionConfigurator( Implicit ):
...
@@ -231,17 +226,16 @@ class WorkflowDefinitionConfigurator( Implicit ):
'script_info' -- a list of mappings describing the scripts which
'script_info' -- a list of mappings describing the scripts which
provide added business logic (see '_extractScripts').
provide added business logic (see '_extractScripts').
"""
"""
workflow_info
[
'manager_bypass'
]
=
bool
(
workflow
.
manager_bypass
)
workflow_info
[
'manager_bypass'
]
=
bool
(
workflow
.
manager_bypass
)
workflow_info
[
'creation_guard'
]
=
self
.
_extractCreationGuard
(
workflow
)
workflow_info
[
'creation_guard'
]
=
self
.
_extractCreationGuard
(
workflow
)
workflow_info
[
'state_variable'
]
=
workflow
.
state_var
workflow_info
[
'state_variable'
]
=
workflow
.
state_var
workflow_info
[
'initial_state'
]
=
workflow
.
initial_state
workflow_info
[
'initial_state'
]
=
workflow
.
initial_state
workflow_info
[
'permissions'
]
=
workflow
.
permissions
workflow_info
[
'permissions'
]
=
workflow
.
permissions
workflow_info
[
'variable_info'
]
=
self
.
_extractVariables
(
workflow
)
workflow_info
[
'variable_info'
]
=
self
.
_extractVariables
(
workflow
)
workflow_info
[
'state_info'
]
=
self
.
_extractStates
(
workflow
)
workflow_info
[
'state_info'
]
=
self
.
_extractStates
(
workflow
)
workflow_info
[
'transition_info'
]
=
self
.
_extractTransitions
(
workflow_info
[
'transition_info'
]
=
self
.
_extractTransitions
(
workflow
)
workflow
)
workflow_info
[
'worklist_info'
]
=
self
.
_extractWorklists
(
workflow
)
workflow_info
[
'worklist_info'
]
=
self
.
_extractWorklists
(
workflow
)
workflow_info
[
'script_info'
]
=
self
.
_extractScripts
(
workflow
)
workflow_info
[
'script_info'
]
=
self
.
_extractScripts
(
workflow
)
security
.
declarePrivate
(
'_extractCreationGuard'
)
security
.
declarePrivate
(
'_extractCreationGuard'
)
def
_extractCreationGuard
(
self
,
workflow
):
def
_extractCreationGuard
(
self
,
workflow
):
...
@@ -249,17 +243,15 @@ class WorkflowDefinitionConfigurator( Implicit ):
...
@@ -249,17 +243,15 @@ class WorkflowDefinitionConfigurator( Implicit ):
if 'creation_guard' is initialized or None
if 'creation_guard' is initialized or None
"""
"""
guard
=
workflow
.
creation_guard
guard
=
workflow
.
creation_guard
if
guard
is
not
None
:
if
guard
is
not
None
:
info
=
{
'guard_permissions'
:
guard
.
permissions
info
=
{
'guard_permissions'
:
guard
.
permissions
,
,
'guard_roles'
:
guard
.
roles
'guard_roles'
:
guard
.
roles
,
,
'guard_groups'
:
guard
.
groups
'guard_groups'
:
guard
.
groups
,
,
'guard_expr'
:
guard
.
getExprText
()
'guard_expr'
:
guard
.
getExprText
()}
}
return
info
return
info
security
.
declarePrivate
(
'_extractVariables'
)
security
.
declarePrivate
(
'_extractVariables'
)
def
_extractVariables
(
self
,
workflow
):
def
_extractVariables
(
self
,
workflow
):
""" Return a sequence of mappings describing DCWorkflow variables.
""" Return a sequence of mappings describing DCWorkflow variables.
o Keys for each mapping will include:
o Keys for each mapping will include:
...
@@ -298,29 +290,27 @@ class WorkflowDefinitionConfigurator( Implicit ):
...
@@ -298,29 +290,27 @@ class WorkflowDefinitionConfigurator( Implicit ):
guard
=
v
.
getInfoGuard
()
guard
=
v
.
getInfoGuard
()
default_type
=
_guessVariableType
(
v
.
default_value
)
default_type
=
_guessVariableType
(
v
.
default_value
)
info
=
{
'id'
:
k
info
=
{
'id'
:
k
,
,
'description'
:
v
.
description
'description'
:
v
.
description
,
,
'for_catalog'
:
bool
(
v
.
for_catalog
)
'for_catalog'
:
bool
(
v
.
for_catalog
),
,
'for_status'
:
bool
(
v
.
for_status
)
'for_status'
:
bool
(
v
.
for_status
),
,
'update_always'
:
bool
(
v
.
update_always
)
'update_always'
:
bool
(
v
.
update_always
),
,
'default_value'
:
v
.
default_value
'default_value'
:
v
.
default_value
,
,
'default_type'
:
default_type
'default_type'
:
default_type
,
,
'default_expr'
:
v
.
getDefaultExprText
()
'default_expr'
:
v
.
getDefaultExprText
(),
,
'guard_permissions'
:
guard
.
permissions
'guard_permissions'
:
guard
.
permissions
,
,
'guard_roles'
:
guard
.
roles
'guard_roles'
:
guard
.
roles
,
,
'guard_groups'
:
guard
.
groups
'guard_groups'
:
guard
.
groups
,
,
'guard_expr'
:
guard
.
getExprText
()
'guard_expr'
:
guard
.
getExprText
()}
}
result
.
append
(
info
)
result
.
append
(
info
)
return
result
return
result
security
.
declarePrivate
(
'_extractStates'
)
security
.
declarePrivate
(
'_extractStates'
)
def
_extractStates
(
self
,
workflow
):
def
_extractStates
(
self
,
workflow
):
""" Return a sequence of mappings describing DCWorkflow states.
""" Return a sequence of mappings describing DCWorkflow states.
o Within the workflow mapping, each 'state_info' mapping has keys:
o Within the workflow mapping, each 'state_info' mapping has keys:
...
@@ -368,37 +358,34 @@ class WorkflowDefinitionConfigurator( Implicit ):
...
@@ -368,37 +358,34 @@ class WorkflowDefinitionConfigurator( Implicit ):
for
k
,
v
in
items
:
for
k
,
v
in
items
:
groups
=
v
.
group_roles
and
list
(
v
.
group_roles
.
items
()
)
or
[]
groups
=
v
.
group_roles
and
list
(
v
.
group_roles
.
items
()
)
or
[]
groups
=
[
x
for
x
in
groups
if
x
[
1
]
]
groups
=
[
x
for
x
in
groups
if
x
[
1
]
]
groups
.
sort
()
groups
.
sort
()
variables
=
list
(
v
.
getVariableValues
()
)
variables
=
list
(
v
.
getVariableValues
()
)
variables
.
sort
()
variables
.
sort
()
v_info
=
[]
v_info
=
[]
for
v_name
,
value
in
variables
:
for
v_name
,
value
in
variables
:
v_info
.
append
(
{
'name'
:
v_name
v_info
.
append
({
'name'
:
v_name
,
,
'type'
:
_guessVariableType
(
value
)
'type'
:
_guessVariableType
(
value
),
,
'value'
:
value
'value'
:
value
})
}
)
info
=
{
'id'
:
k
,
'title'
:
v
.
title
,
'description'
:
v
.
description
,
'transitions'
:
v
.
transitions
,
'permissions'
:
self
.
_extractStatePermissions
(
v
)
,
'groups'
:
groups
,
'variables'
:
v_info
}
result
.
append
(
info
)
return
result
info
=
{
'id'
:
k
,
'title'
:
v
.
title
,
'description'
:
v
.
description
,
'transitions'
:
v
.
transitions
,
'permissions'
:
self
.
_extractStatePermissions
(
v
),
'groups'
:
groups
,
'variables'
:
v_info
}
security
.
declarePrivate
(
'_extractStatePermissions'
)
result
.
append
(
info
)
def
_extractStatePermissions
(
self
,
state
):
return
result
security
.
declarePrivate
(
'_extractStatePermissions'
)
def
_extractStatePermissions
(
self
,
state
):
""" Return a sequence of mappings for the permissions in a state.
""" Return a sequence of mappings for the permissions in a state.
o Each mapping has the keys:
o Each mapping has the keys:
...
@@ -417,18 +404,14 @@ class WorkflowDefinitionConfigurator( Implicit ):
...
@@ -417,18 +404,14 @@ class WorkflowDefinitionConfigurator( Implicit ):
items
.
sort
()
items
.
sort
()
for
k
,
v
in
items
:
for
k
,
v
in
items
:
result
.
append
({
'name'
:
k
,
result
.
append
(
{
'name'
:
k
'roles'
:
v
,
,
'roles'
:
v
'acquired'
:
not
isinstance
(
v
,
tuple
)})
,
'acquired'
:
not
isinstance
(
v
,
tuple
)
}
)
return
result
return
result
security
.
declarePrivate
(
'_extractTransitions'
)
security
.
declarePrivate
(
'_extractTransitions'
)
def
_extractTransitions
(
self
,
workflow
):
def
_extractTransitions
(
self
,
workflow
):
""" Return a sequence of mappings describing DCWorkflow transitions.
""" Return a sequence of mappings describing DCWorkflow transitions.
o Each mapping has the keys:
o Each mapping has the keys:
...
@@ -492,33 +475,31 @@ class WorkflowDefinitionConfigurator( Implicit ):
...
@@ -492,33 +475,31 @@ class WorkflowDefinitionConfigurator( Implicit ):
v_info
=
[]
v_info
=
[]
for
v_name
,
expr
in
v
.
getVariableExprs
():
for
v_name
,
expr
in
v
.
getVariableExprs
():
v_info
.
append
(
{
'name'
:
v_name
,
'expr'
:
expr
}
)
v_info
.
append
({
'name'
:
v_name
,
'expr'
:
expr
})
info
=
{
'id'
:
k
info
=
{
'id'
:
k
,
,
'title'
:
v
.
title
'title'
:
v
.
title
,
,
'description'
:
v
.
description
'description'
:
v
.
description
,
,
'new_state_id'
:
v
.
new_state_id
'new_state_id'
:
v
.
new_state_id
,
,
'trigger_type'
:
TRIGGER_TYPES
[
v
.
trigger_type
]
'trigger_type'
:
TRIGGER_TYPES
[
v
.
trigger_type
],
,
'script_name'
:
v
.
script_name
'script_name'
:
v
.
script_name
,
,
'after_script_name'
:
v
.
after_script_name
'after_script_name'
:
v
.
after_script_name
,
,
'actbox_name'
:
v
.
actbox_name
'actbox_name'
:
v
.
actbox_name
,
,
'actbox_url'
:
v
.
actbox_url
'actbox_url'
:
v
.
actbox_url
,
,
'actbox_icon'
:
v
.
actbox_icon
'actbox_icon'
:
v
.
actbox_icon
,
,
'actbox_category'
:
v
.
actbox_category
'actbox_category'
:
v
.
actbox_category
,
,
'variables'
:
v_info
'variables'
:
v_info
,
,
'guard_permissions'
:
guard
.
permissions
'guard_permissions'
:
guard
.
permissions
,
,
'guard_roles'
:
guard
.
roles
'guard_roles'
:
guard
.
roles
,
,
'guard_groups'
:
guard
.
groups
'guard_groups'
:
guard
.
groups
,
,
'guard_expr'
:
guard
.
getExprText
()
'guard_expr'
:
guard
.
getExprText
()}
}
result
.
append
(
info
)
result
.
append
(
info
)
return
result
return
result
security
.
declarePrivate
(
'_extractWorklists'
)
security
.
declarePrivate
(
'_extractWorklists'
)
def
_extractWorklists
(
self
,
workflow
):
def
_extractWorklists
(
self
,
workflow
):
""" Return a sequence of mappings describing DCWorkflow transitions.
""" Return a sequence of mappings describing DCWorkflow transitions.
o Each mapping has the keys:
o Each mapping has the keys:
...
@@ -538,7 +519,7 @@ class WorkflowDefinitionConfigurator( Implicit ):
...
@@ -538,7 +519,7 @@ class WorkflowDefinitionConfigurator( Implicit ):
'actbox_url' -- the URL of the "action" corresponding to the
'actbox_url' -- the URL of the "action" corresponding to the
worklist
worklist
'actbox_icon' -- the icon URL of the "action" corresponding to
'actbox_icon' -- the icon URL of the "action" corresponding to
the worklist
the worklist
'actbox_category' -- the category of the "action" corresponding
'actbox_category' -- the category of the "action" corresponding
...
@@ -562,30 +543,28 @@ class WorkflowDefinitionConfigurator( Implicit ):
...
@@ -562,30 +543,28 @@ class WorkflowDefinitionConfigurator( Implicit ):
guard
=
v
.
getGuard
()
guard
=
v
.
getGuard
()
var_match
=
[
(
id
,
v
.
getVarMatchText
(
id
)
)
var_match
=
[
(
id
,
v
.
getVarMatchText
(
id
))
for
id
in
v
.
getVarMatchKeys
()
]
for
id
in
v
.
getVarMatchKeys
()
]
info
=
{
'id'
:
k
,
'title'
:
v
.
title
,
'description'
:
v
.
description
,
'var_match'
:
var_match
,
'actbox_name'
:
v
.
actbox_name
,
'actbox_url'
:
v
.
actbox_url
,
'actbox_icon'
:
v
.
actbox_icon
,
'actbox_category'
:
v
.
actbox_category
,
'guard_permissions'
:
guard
.
permissions
,
'guard_roles'
:
guard
.
roles
,
'guard_groups'
:
guard
.
groups
,
'guard_expr'
:
guard
.
getExprText
()
}
result
.
append
(
info
)
return
result
info
=
{
'id'
:
k
,
'title'
:
v
.
title
,
'description'
:
v
.
description
,
'var_match'
:
var_match
,
'actbox_name'
:
v
.
actbox_name
,
'actbox_url'
:
v
.
actbox_url
,
'actbox_icon'
:
v
.
actbox_icon
,
'actbox_category'
:
v
.
actbox_category
,
'guard_permissions'
:
guard
.
permissions
,
'guard_roles'
:
guard
.
roles
,
'guard_groups'
:
guard
.
groups
,
'guard_expr'
:
guard
.
getExprText
()}
security
.
declarePrivate
(
'_extractScripts'
)
result
.
append
(
info
)
def
_extractScripts
(
self
,
workflow
):
return
result
security
.
declarePrivate
(
'_extractScripts'
)
def
_extractScripts
(
self
,
workflow
):
""" Return a sequence of mappings describing DCWorkflow scripts.
""" Return a sequence of mappings describing DCWorkflow scripts.
o Each mapping has the keys:
o Each mapping has the keys:
...
@@ -613,7 +592,7 @@ class WorkflowDefinitionConfigurator( Implicit ):
...
@@ -613,7 +592,7 @@ class WorkflowDefinitionConfigurator( Implicit ):
for
k
,
v
in
items
:
for
k
,
v
in
items
:
filename
=
_getScriptFilename
(
workflow
.
getId
(),
k
,
v
.
meta_type
)
filename
=
_getScriptFilename
(
workflow
.
getId
(),
k
,
v
.
meta_type
)
module
=
''
module
=
''
function
=
''
function
=
''
...
@@ -621,342 +600,301 @@ class WorkflowDefinitionConfigurator( Implicit ):
...
@@ -621,342 +600,301 @@ class WorkflowDefinitionConfigurator( Implicit ):
module
=
v
.
module
()
module
=
v
.
module
()
function
=
v
.
function
()
function
=
v
.
function
()
info
=
{
'id'
:
k
info
=
{
'id'
:
k
,
,
'meta_type'
:
v
.
meta_type
'meta_type'
:
v
.
meta_type
,
,
'module'
:
module
'module'
:
module
,
,
'function'
:
function
'function'
:
function
,
,
'filename'
:
filename
'filename'
:
filename
}
}
result
.
append
(
info
)
result
.
append
(
info
)
return
result
return
result
InitializeClass
(
WorkflowDefinitionConfigurator
)
InitializeClass
(
WorkflowDefinitionConfigurator
)
def
_getScriptFilename
(
workflow_id
,
script_id
,
meta_type
):
def
_getScriptFilename
(
workflow_id
,
script_id
,
meta_type
):
""" Return the name of the file which holds the script.
""" Return the name of the file which holds the script.
"""
"""
wf_dir
=
workflow_id
.
replace
(
' '
,
'_'
)
wf_dir
=
workflow_id
.
replace
(
' '
,
'_'
)
suffix
=
_METATYPE_SUFFIXES
.
get
(
meta_type
,
None
)
suffix
=
_METATYPE_SUFFIXES
.
get
(
meta_type
,
None
)
if
suffix
is
None
:
if
suffix
is
None
:
return
''
return
''
return
'workflows/%s/scripts/%s.%s'
%
(
wf_dir
,
script_id
,
suffix
)
return
'workflows/%s/scripts/%s.%s'
%
(
wf_dir
,
script_id
,
suffix
)
def
_extractCreationGuard
(
root
,
encoding
=
'utf-8'
)
:
def
_extractCreationGuard
(
root
,
encoding
=
'utf-8'
):
icc
=
root
.
getElementsByTagName
(
'instance-creation-conditions'
)
icc
=
root
.
getElementsByTagName
(
'instance-creation-conditions'
)
assert
len
(
icc
)
<=
1
assert
len
(
icc
)
<=
1
if
icc
:
if
icc
:
parent
=
icc
[
0
]
parent
=
icc
[
0
]
return
_extractGuardNode
(
parent
,
encoding
)
return
_extractGuardNode
(
parent
,
encoding
)
else
:
else
:
return
None
return
None
def
_extractStateNodes
(
root
,
encoding
=
'utf-8'
):
def
_extractStateNodes
(
root
,
encoding
=
'utf-8'
):
result
=
[]
result
=
[]
for
s_node
in
root
.
getElementsByTagName
(
'state'
):
for
s_node
in
root
.
getElementsByTagName
(
'state'
):
info
=
{
'state_id'
:
_getNodeAttribute
(
s_node
,
'state_id'
,
encoding
),
info
=
{
'state_id'
:
_getNodeAttribute
(
s_node
,
'state_id'
,
encoding
)
'title'
:
_getNodeAttribute
(
s_node
,
'title'
,
encoding
),
,
'title'
:
_getNodeAttribute
(
s_node
,
'title'
,
encoding
)
'description'
:
_extractDescriptionNode
(
s_node
,
encoding
)}
,
'description'
:
_extractDescriptionNode
(
s_node
,
encoding
)
}
info
[
'transitions'
]
=
[
_getNodeAttribute
(
x
,
'transition_id'
info
[
'transitions'
]
=
[
_getNodeAttribute
(
x
,
'transition_id'
,
encoding
)
,
encoding
)
for
x
in
s_node
.
getElementsByTagName
(
for
x
in
s_node
.
getElementsByTagName
(
'exit-transition'
)
]
'exit-transition'
)
]
info
[
'permissions'
]
=
permission_map
=
{}
info
[
'permissions'
]
=
permission_map
=
{}
for
p_map
in
s_node
.
getElementsByTagName
(
'permission-map'
):
for
p_map
in
s_node
.
getElementsByTagName
(
'permission-map'
):
name
=
_getNodeAttribute
(
p_map
,
'name'
,
encoding
)
name
=
_getNodeAttribute
(
p_map
,
'name'
,
encoding
)
acquired
=
_queryNodeAttributeBoolean
(
p_map
,
'acquired'
,
False
)
acquired
=
_queryNodeAttributeBoolean
(
p_map
,
'acquired'
,
False
)
roles
=
[
_coalesceTextNodeChildren
(
x
,
encoding
)
roles
=
[
_coalesceTextNodeChildren
(
x
,
encoding
)
for
x
in
p_map
.
getElementsByTagName
(
for
x
in
p_map
.
getElementsByTagName
(
'permission-role'
)
]
'permission-role'
)
]
if
not
acquired
:
if
not
acquired
:
roles
=
tuple
(
roles
)
roles
=
tuple
(
roles
)
permission_map
[
name
]
=
roles
permission_map
[
name
]
=
roles
info
[
'groups'
]
=
group_map
=
[]
info
[
'groups'
]
=
group_map
=
[]
for
g_map
in
s_node
.
getElementsByTagName
(
'group-map'
):
for
g_map
in
s_node
.
getElementsByTagName
(
'group-map'
):
name
=
_getNodeAttribute
(
g_map
,
'name'
,
encoding
)
name
=
_getNodeAttribute
(
g_map
,
'name'
,
encoding
)
roles
=
[
_coalesceTextNodeChildren
(
x
,
encoding
)
roles
=
[
_coalesceTextNodeChildren
(
x
,
encoding
)
for
x
in
g_map
.
getElementsByTagName
(
for
x
in
g_map
.
getElementsByTagName
(
'group-role'
)
]
'group-role'
)
]
group_map
.
append
(
(
name
,
tuple
(
roles
)
)
)
group_map
.
append
(
(
name
,
tuple
(
roles
))
)
info
[
'variables'
]
=
var_map
=
{}
info
[
'variables'
]
=
var_map
=
{}
for
assignment
in
s_node
.
getElementsByTagName
(
'assignment'
):
for
assignment
in
s_node
.
getElementsByTagName
(
'assignment'
):
name
=
_getNodeAttribute
(
assignment
,
'name'
,
encoding
)
name
=
_getNodeAttribute
(
assignment
,
'name'
,
encoding
)
type_id
=
_getNodeAttribute
(
assignment
,
'type'
,
encoding
)
type_id
=
_getNodeAttribute
(
assignment
,
'type'
,
encoding
)
value
=
_coalesceTextNodeChildren
(
assignment
,
encoding
)
value
=
_coalesceTextNodeChildren
(
assignment
,
encoding
)
var_map
[
name
]
=
{
'name'
:
name
var_map
[
name
]
=
{
'name'
:
name
,
'type'
:
type_id
,
'value'
:
value
}
,
'type'
:
type_id
,
'value'
:
value
}
result
.
append
(
info
)
result
.
append
(
info
)
return
result
return
result
def
_extractTransitionNodes
(
root
,
encoding
=
'utf-8'
):
def
_extractTransitionNodes
(
root
,
encoding
=
'utf-8'
):
result
=
[]
result
=
[]
for
t_node
in
root
.
getElementsByTagName
(
'transition'
):
for
t_node
in
root
.
getElementsByTagName
(
'transition'
):
info
=
{
'transition_id'
:
_getNodeAttribute
(
t_node
,
'transition_id'
info
=
{
'transition_id'
:
_getNodeAttribute
(
t_node
,
'transition_id'
,
,
encoding
)
encoding
),
,
'title'
:
_getNodeAttribute
(
t_node
,
'title'
,
encoding
)
'title'
:
_getNodeAttribute
(
t_node
,
'title'
,
encoding
),
,
'description'
:
_extractDescriptionNode
(
t_node
,
encoding
)
'description'
:
_extractDescriptionNode
(
t_node
,
encoding
),
,
'new_state'
:
_getNodeAttribute
(
t_node
,
'new_state'
'new_state'
:
_getNodeAttribute
(
t_node
,
'new_state'
,
encoding
),
,
encoding
)
'trigger'
:
_getNodeAttribute
(
t_node
,
'trigger'
,
encoding
),
,
'trigger'
:
_getNodeAttribute
(
t_node
,
'trigger'
,
encoding
)
'before_script'
:
_getNodeAttribute
(
t_node
,
'before_script'
,
,
'before_script'
:
_getNodeAttribute
(
t_node
,
'before_script'
encoding
),
,
encoding
)
'after_script'
:
_getNodeAttribute
(
t_node
,
'after_script'
,
,
'after_script'
:
_getNodeAttribute
(
t_node
,
'after_script'
encoding
),
,
encoding
)
'action'
:
_extractActionNode
(
t_node
,
encoding
),
,
'action'
:
_extractActionNode
(
t_node
,
encoding
)
'guard'
:
_extractGuardNode
(
t_node
,
encoding
)}
,
'guard'
:
_extractGuardNode
(
t_node
,
encoding
)
}
info
[
'variables'
]
=
var_map
=
{}
info
[
'variables'
]
=
var_map
=
{}
for
assignment
in
t_node
.
getElementsByTagName
(
'assignment'
):
for
assignment
in
t_node
.
getElementsByTagName
(
'assignment'
):
name
=
_getNodeAttribute
(
assignment
,
'name'
,
encoding
)
name
=
_getNodeAttribute
(
assignment
,
'name'
,
encoding
)
expr
=
_coalesceTextNodeChildren
(
assignment
,
encoding
)
expr
=
_coalesceTextNodeChildren
(
assignment
,
encoding
)
var_map
[
name
]
=
expr
var_map
[
name
]
=
expr
result
.
append
(
info
)
result
.
append
(
info
)
return
result
return
result
def
_extractVariableNodes
(
root
,
encoding
=
'utf-8'
):
def
_extractVariableNodes
(
root
,
encoding
=
'utf-8'
):
result
=
[]
result
=
[]
for
v_node
in
root
.
getElementsByTagName
(
'variable'
):
for
v_node
in
root
.
getElementsByTagName
(
'variable'
):
info
=
{
'variable_id'
:
_getNodeAttribute
(
v_node
,
'variable_id'
,
encoding
)
,
'description'
:
_extractDescriptionNode
(
v_node
,
encoding
)
,
'for_catalog'
:
_queryNodeAttributeBoolean
(
v_node
,
'for_catalog'
,
False
)
,
'for_status'
:
_queryNodeAttributeBoolean
(
v_node
,
'for_status'
,
False
)
,
'update_always'
:
_queryNodeAttributeBoolean
(
v_node
,
'update_always'
,
False
)
,
'default'
:
_extractDefaultNode
(
v_node
,
encoding
)
,
'guard'
:
_extractGuardNode
(
v_node
,
encoding
)
}
result
.
append
(
info
)
return
result
info
=
{
'variable_id'
:
_getNodeAttribute
(
v_node
,
'variable_id'
,
encoding
),
'description'
:
_extractDescriptionNode
(
v_node
,
encoding
),
'for_catalog'
:
_queryNodeAttributeBoolean
(
v_node
,
'for_catalog'
,
False
),
'for_status'
:
_queryNodeAttributeBoolean
(
v_node
,
'for_status'
,
False
),
'update_always'
:
_queryNodeAttributeBoolean
(
v_node
,
'update_always'
,
False
),
'default'
:
_extractDefaultNode
(
v_node
,
encoding
),
'guard'
:
_extractGuardNode
(
v_node
,
encoding
)}
result
.
append
(
info
)
def
_extractWorklistNodes
(
root
,
encoding
=
'utf-8'
):
return
result
def
_extractWorklistNodes
(
root
,
encoding
=
'utf-8'
):
result
=
[]
result
=
[]
for
w_node
in
root
.
getElementsByTagName
(
'worklist'
):
for
w_node
in
root
.
getElementsByTagName
(
'worklist'
):
info
=
{
'worklist_id'
:
_getNodeAttribute
(
w_node
,
'worklist_id'
info
=
{
'worklist_id'
:
_getNodeAttribute
(
w_node
,
'worklist_id'
,
,
encoding
)
encoding
),
,
'title'
:
_getNodeAttribute
(
w_node
,
'title'
,
encoding
)
'title'
:
_getNodeAttribute
(
w_node
,
'title'
,
encoding
),
,
'description'
:
_extractDescriptionNode
(
w_node
,
encoding
)
'description'
:
_extractDescriptionNode
(
w_node
,
encoding
),
,
'match'
:
_extractMatchNode
(
w_node
,
encoding
)
'match'
:
_extractMatchNode
(
w_node
,
encoding
),
,
'action'
:
_extractActionNode
(
w_node
,
encoding
)
'action'
:
_extractActionNode
(
w_node
,
encoding
),
,
'guard'
:
_extractGuardNode
(
w_node
,
encoding
)
'guard'
:
_extractGuardNode
(
w_node
,
encoding
)}
}
result
.
append
(
info
)
result
.
append
(
info
)
return
result
return
result
def
_extractScriptNodes
(
root
,
encoding
=
'utf-8'
):
def
_extractScriptNodes
(
root
,
encoding
=
'utf-8'
):
result
=
[]
result
=
[]
for
s_node
in
root
.
getElementsByTagName
(
'script'
):
for
s_node
in
root
.
getElementsByTagName
(
'script'
):
try
:
try
:
function
=
_getNodeAttribute
(
s_node
,
'function'
)
function
=
_getNodeAttribute
(
s_node
,
'function'
)
except
ValueError
:
except
ValueError
:
function
=
''
function
=
''
try
:
try
:
module
=
_getNodeAttribute
(
s_node
,
'module'
)
module
=
_getNodeAttribute
(
s_node
,
'module'
)
except
ValueError
:
except
ValueError
:
module
=
''
module
=
''
info
=
{
'script_id'
:
_getNodeAttribute
(
s_node
,
'script_id'
)
info
=
{
'script_id'
:
_getNodeAttribute
(
s_node
,
'script_id'
),
,
'meta_type'
:
_getNodeAttribute
(
s_node
,
'type'
,
encoding
)
'meta_type'
:
_getNodeAttribute
(
s_node
,
'type'
,
encoding
),
,
'function'
:
function
'function'
:
function
,
,
'module'
:
module
'module'
:
module
}
}
filename
=
_queryNodeAttribute
(
s_node
,
'filename'
,
None
,
encoding
)
filename
=
_queryNodeAttribute
(
s_node
,
'filename'
,
None
,
encoding
)
if
filename
is
not
None
:
if
filename
is
not
None
:
info
[
'filename'
]
=
filename
info
[
'filename'
]
=
filename
result
.
append
(
info
)
result
.
append
(
info
)
return
result
return
result
def
_extractPermissionNodes
(
root
,
encoding
=
'utf-8'
):
def
_extractPermissionNodes
(
root
,
encoding
=
'utf-8'
):
result
=
[]
result
=
[]
for
p_node
in
root
.
getElementsByTagName
(
'permission'
):
for
p_node
in
root
.
getElementsByTagName
(
'permission'
):
result
.
append
(
_coalesceTextNodeChildren
(
p_node
,
encoding
)
)
result
.
append
(
_coalesceTextNodeChildren
(
p_node
,
encoding
)
)
return
result
return
result
def
_extractActionNode
(
parent
,
encoding
=
'utf-8'
):
def
_extractActionNode
(
parent
,
encoding
=
'utf-8'
):
nodes
=
parent
.
getElementsByTagName
(
'action'
)
assert
len
(
nodes
)
<=
1
,
nodes
nodes
=
parent
.
getElementsByTagName
(
'action'
)
if
len
(
nodes
)
<
1
:
assert
len
(
nodes
)
<=
1
,
nodes
return
{
'name'
:
''
,
'url'
:
''
,
'category'
:
''
,
'icon'
:
''
}
if
len
(
nodes
)
<
1
:
node
=
nodes
[
0
]
return
{
'name'
:
''
,
'url'
:
''
,
'category'
:
''
,
'icon'
:
''
}
node
=
nodes
[
0
]
return
{
'name'
:
_coalesceTextNodeChildren
(
node
,
encoding
),
'url'
:
_getNodeAttribute
(
node
,
'url'
,
encoding
),
'category'
:
_getNodeAttribute
(
node
,
'category'
,
encoding
),
'icon'
:
_queryNodeAttribute
(
node
,
'icon'
,
''
,
encoding
)}
return
{
'name'
:
_coalesceTextNodeChildren
(
node
,
encoding
)
def
_extractGuardNode
(
parent
,
encoding
=
'utf-8'
):
,
'url'
:
_getNodeAttribute
(
node
,
'url'
,
encoding
)
nodes
=
parent
.
getElementsByTagName
(
'guard'
)
,
'category'
:
_getNodeAttribute
(
node
,
'category'
,
encoding
)
assert
len
(
nodes
)
<=
1
,
nodes
,
'icon'
:
_queryNodeAttribute
(
node
,
'icon'
,
''
,
encoding
)
}
def
_extractGuardNode
(
parent
,
encoding
=
'utf-8'
):
if
len
(
nodes
)
<
1
:
return
{
'permissions'
:
(),
'roles'
:
(),
'groups'
:
(),
'expr'
:
''
}
nodes
=
parent
.
getElementsByTagName
(
'guard'
)
node
=
nodes
[
0
]
assert
len
(
nodes
)
<=
1
,
nodes
if
len
(
nodes
)
<
1
:
expr_nodes
=
node
.
getElementsByTagName
(
'guard-expression'
)
return
{
'permissions'
:
(),
'roles'
:
(),
'groups'
:
(),
'expr'
:
''
}
assert
(
len
(
expr_nodes
)
<=
1
)
node
=
nodes
[
0
]
expr_text
=
expr_nodes
and
_coalesceTextNodeChildren
(
expr_nodes
[
0
],
encoding
)
or
''
expr_nodes
=
node
.
getElementsByTagName
(
'guard-expression'
)
return
{
'permissions'
:
[
_coalesceTextNodeChildren
(
x
,
encoding
)
assert
(
len
(
expr_nodes
)
<=
1
)
for
x
in
node
.
getElementsByTagName
(
'guard-permission'
)
],
'roles'
:
[
_coalesceTextNodeChildren
(
x
,
encoding
)
for
x
in
node
.
getElementsByTagName
(
'guard-role'
)
],
'groups'
:
[
_coalesceTextNodeChildren
(
x
,
encoding
)
for
x
in
node
.
getElementsByTagName
(
'guard-group'
)
],
'expression'
:
expr_text
}
expr_text
=
expr_nodes
and
_coalesceTextNodeChildren
(
expr_nodes
[
0
]
def
_extractDefaultNode
(
parent
,
encoding
=
'utf-8'
):
,
encoding
nodes
=
parent
.
getElementsByTagName
(
'default'
)
)
or
''
assert
len
(
nodes
)
<=
1
,
nodes
return
{
'permissions'
:
[
_coalesceTextNodeChildren
(
x
,
encoding
)
if
len
(
nodes
)
<
1
:
for
x
in
node
.
getElementsByTagName
(
return
{
'value'
:
''
,
'expression'
:
''
,
'type'
:
'n/a'
}
'guard-permission'
)
]
,
'roles'
:
[
_coalesceTextNodeChildren
(
x
,
encoding
)
for
x
in
node
.
getElementsByTagName
(
'guard-role'
)
]
,
'groups'
:
[
_coalesceTextNodeChildren
(
x
,
encoding
)
for
x
in
node
.
getElementsByTagName
(
'guard-group'
)
]
,
'expression'
:
expr_text
}
def
_extractDefaultNode
(
parent
,
encoding
=
'utf-8'
):
node
=
nodes
[
0
]
nodes
=
parent
.
getElementsByTagName
(
'default'
)
value_nodes
=
node
.
getElementsByTagName
(
'value'
)
assert
len
(
nodes
)
<=
1
,
nodes
assert
(
len
(
value_nodes
)
<=
1
)
if
len
(
nodes
)
<
1
:
return
{
'value'
:
''
,
'expression'
:
''
,
'type'
:
'n/a'
}
node
=
nodes
[
0
]
value_nodes
=
node
.
getElementsByTagName
(
'value'
)
assert
(
len
(
value_nodes
)
<=
1
)
value_type
=
'n/a'
value_type
=
'n/a'
if
value_nodes
:
if
value_nodes
:
value_type
=
value_nodes
[
0
].
getAttribute
(
'type'
)
or
'n/a'
value_type
=
value_nodes
[
0
].
getAttribute
(
'type'
)
or
'n/a'
value_text
=
value_nodes
and
_coalesceTextNodeChildren
(
value_nodes
[
0
]
,
encoding
)
or
''
expr_nodes
=
node
.
getElementsByTagName
(
'expression'
)
value_text
=
value_nodes
and
_coalesceTextNodeChildren
(
value_nodes
[
0
],
assert
(
len
(
expr_nodes
)
<=
1
)
encoding
)
or
''
expr_text
=
expr_nodes
and
_coalesceTextNodeChildren
(
expr_nodes
[
0
]
expr_nodes
=
node
.
getElementsByTagName
(
'expression'
)
,
encoding
assert
(
len
(
expr_nodes
)
<=
1
)
)
or
''
return
{
'value'
:
value_text
expr_text
=
expr_nodes
and
_coalesceTextNodeChildren
(
expr_nodes
[
0
],
,
'type'
:
value_type
encoding
)
or
''
,
'expression'
:
expr_text
}
_SEMICOLON_LIST_SPLITTER
=
re
.
compile
(
r';[ ]*'
)
return
{
'value'
:
value_text
,
'type'
:
value_type
,
'expression'
:
expr_text
}
def
_extractMatchNode
(
parent
,
encoding
=
'utf-8'
):
_SEMICOLON_LIST_SPLITTER
=
re
.
compile
(
r';[ ]*'
)
nodes
=
parent
.
getElementsByTagName
(
'match'
)
def
_extractMatchNode
(
parent
,
encoding
=
'utf-8'
):
nodes
=
parent
.
getElementsByTagName
(
'match'
)
result
=
{}
result
=
{}
for
node
in
nodes
:
for
node
in
nodes
:
name
=
_getNodeAttribute
(
node
,
'name'
,
encoding
)
name
=
_getNodeAttribute
(
node
,
'name'
,
encoding
)
values
=
_getNodeAttribute
(
node
,
'values'
,
encoding
)
values
=
_getNodeAttribute
(
node
,
'values'
,
encoding
)
result
[
name
]
=
_SEMICOLON_LIST_SPLITTER
.
split
(
values
)
result
[
name
]
=
_SEMICOLON_LIST_SPLITTER
.
split
(
values
)
return
result
return
result
def
_guessVariableType
(
value
):
def
_guessVariableType
(
value
):
from
DateTime.DateTime
import
DateTime
from
DateTime.DateTime
import
DateTime
if
value
is
None
:
if
value
is
None
:
return
'none'
return
'none'
if
isinstance
(
value
,
DateTime
):
if
isinstance
(
value
,
DateTime
):
return
'datetime'
return
'datetime'
if
isinstance
(
value
,
bool
):
if
isinstance
(
value
,
bool
):
return
'bool'
return
'bool'
if
isinstance
(
value
,
int
):
if
isinstance
(
value
,
int
):
return
'int'
return
'int'
if
isinstance
(
value
,
float
):
if
isinstance
(
value
,
float
):
return
'float'
return
'float'
if
isinstance
(
value
,
basestring
):
if
isinstance
(
value
,
basestring
):
return
'string'
return
'string'
return
'unknown'
return
'unknown'
def
_convertVariableValue
(
value
,
type_id
):
def
_convertVariableValue
(
value
,
type_id
):
from
DateTime.DateTime
import
DateTime
from
DateTime.DateTime
import
DateTime
if
type_id
==
'none'
:
if
type_id
==
'none'
:
...
@@ -964,24 +902,24 @@ def _convertVariableValue( value, type_id ):
...
@@ -964,24 +902,24 @@ def _convertVariableValue( value, type_id ):
if
type_id
==
'datetime'
:
if
type_id
==
'datetime'
:
return
DateTime
(
value
)
return
DateTime
(
value
)
if
type_id
==
'bool'
:
if
type_id
==
'bool'
:
if
isinstance
(
value
,
basestring
):
if
isinstance
(
value
,
basestring
):
value
=
str
(
value
).
lower
()
value
=
str
(
value
).
lower
()
return
value
in
(
'true'
,
'yes'
,
'1'
)
return
value
in
(
'true'
,
'yes'
,
'1'
)
else
:
else
:
return
bool
(
value
)
return
bool
(
value
)
if
type_id
==
'int'
:
if
type_id
==
'int'
:
return
int
(
value
)
return
int
(
value
)
if
type_id
==
'float'
:
if
type_id
==
'float'
:
return
float
(
value
)
return
float
(
value
)
return
value
return
value
...
@@ -989,26 +927,24 @@ from Products.PythonScripts.PythonScript import PythonScript
...
@@ -989,26 +927,24 @@ from Products.PythonScripts.PythonScript import PythonScript
from
Products.ExternalMethod.ExternalMethod
import
ExternalMethod
from
Products.ExternalMethod.ExternalMethod
import
ExternalMethod
from
OFS.DTMLMethod
import
DTMLMethod
from
OFS.DTMLMethod
import
DTMLMethod
_METATYPE_SUFFIXES
=
\
_METATYPE_SUFFIXES
=
{
{
PythonScript
.
meta_type
:
'py'
PythonScript
.
meta_type
:
'py'
,
,
DTMLMethod
.
meta_type
:
'dtml'
DTMLMethod
.
meta_type
:
'dtml'
}
}
def
_initDCWorkflow
(
workflow
,
def
_initDCWorkflow
(
workflow
title
,
,
title
description
,
,
description
manager_bypass
,
,
manager_bypass
creation_guard
,
,
creation_guard
state_variable
,
,
state_variable
initial_state
,
,
initial_state
states
,
,
states
transitions
,
,
transitions
variables
,
,
variables
worklists
,
,
worklists
permissions
,
,
permissions
scripts
,
,
scripts
context
):
,
context
):
""" Initialize a DC Workflow using values parsed from XML.
""" Initialize a DC Workflow using values parsed from XML.
"""
"""
workflow
.
title
=
title
workflow
.
title
=
title
...
@@ -1021,208 +957,187 @@ def _initDCWorkflow( workflow
...
@@ -1021,208 +957,187 @@ def _initDCWorkflow( workflow
permissions
.
sort
()
permissions
.
sort
()
workflow
.
permissions
=
tuple
(
permissions
)
workflow
.
permissions
=
tuple
(
permissions
)
_initDCWorkflowCreationGuard
(
workflow
,
creation_guard
)
_initDCWorkflowCreationGuard
(
workflow
,
creation_guard
)
_initDCWorkflowVariables
(
workflow
,
variables
)
_initDCWorkflowVariables
(
workflow
,
variables
)
_initDCWorkflowStates
(
workflow
,
states
)
_initDCWorkflowStates
(
workflow
,
states
)
_initDCWorkflowTransitions
(
workflow
,
transitions
)
_initDCWorkflowTransitions
(
workflow
,
transitions
)
_initDCWorkflowWorklists
(
workflow
,
worklists
)
_initDCWorkflowWorklists
(
workflow
,
worklists
)
_initDCWorkflowScripts
(
workflow
,
scripts
,
context
)
_initDCWorkflowScripts
(
workflow
,
scripts
,
context
)
def
_initDCWorkflowCreationGuard
(
workflow
,
guard
):
def
_initDCWorkflowCreationGuard
(
workflow
,
guard
):
"""Initialize Instance creation conditions guard
"""Initialize Instance creation conditions guard
"""
"""
if
guard
is
None
:
if
guard
is
None
:
workflow
.
creation_guard
=
None
workflow
.
creation_guard
=
None
else
:
else
:
props
=
{
'guard_roles'
:
';'
.
join
(
guard
[
'roles'
]
)
props
=
{
'guard_roles'
:
';'
.
join
(
guard
[
'roles'
]),
,
'guard_permissions'
:
';'
.
join
(
guard
[
'permissions'
]
)
'guard_permissions'
:
';'
.
join
(
guard
[
'permissions'
]),
,
'guard_groups'
:
';'
.
join
(
guard
[
'groups'
]
)
'guard_groups'
:
';'
.
join
(
guard
[
'groups'
]),
,
'guard_expr'
:
guard
[
'expression'
]
'guard_expr'
:
guard
[
'expression'
]}
}
g
=
Guard
()
g
=
Guard
()
g
.
changeFromProperties
(
props
)
g
.
changeFromProperties
(
props
)
workflow
.
creation_guard
=
g
workflow
.
creation_guard
=
g
def
_initDCWorkflowVariables
(
workflow
,
variables
):
def
_initDCWorkflowVariables
(
workflow
,
variables
):
""" Initialize DCWorkflow variables
""" Initialize DCWorkflow variables
"""
"""
from
Products.DCWorkflow.Variables
import
VariableDefinition
from
Products.DCWorkflow.Variables
import
VariableDefinition
for
v_info
in
variables
:
for
v_info
in
variables
:
id
=
str
(
v_info
[
'variable_id'
]
)
# no unicode!
id
=
str
(
v_info
[
'variable_id'
]
)
# no unicode!
if
not
workflow
.
variables
.
has_key
(
id
)
:
if
not
id
in
workflow
.
variables
:
v
=
VariableDefinition
(
id
)
v
=
VariableDefinition
(
id
)
workflow
.
variables
.
_setObject
(
id
,
v
)
workflow
.
variables
.
_setObject
(
id
,
v
)
v
=
workflow
.
variables
.
_getOb
(
id
)
v
=
workflow
.
variables
.
_getOb
(
id
)
guard
=
v_info
[
'guard'
]
guard
=
v_info
[
'guard'
]
props
=
{
'guard_roles'
:
';'
.
join
(
guard
[
'roles'
]
)
props
=
{
'guard_roles'
:
';'
.
join
(
guard
[
'roles'
]),
,
'guard_permissions'
:
';'
.
join
(
guard
[
'permissions'
]
)
'guard_permissions'
:
';'
.
join
(
guard
[
'permissions'
]),
,
'guard_groups'
:
';'
.
join
(
guard
[
'groups'
]
)
'guard_groups'
:
';'
.
join
(
guard
[
'groups'
]),
,
'guard_expr'
:
guard
[
'expression'
]
'guard_expr'
:
guard
[
'expression'
]}
}
default
=
v_info
[
'default'
]
default
=
v_info
[
'default'
]
default_value
=
_convertVariableValue
(
default
[
'value'
],
default_value
=
_convertVariableValue
(
default
[
'value'
]
default
[
'type'
])
,
default
[
'type'
]
)
v
.
setProperties
(
description
=
v_info
[
'description'
],
v
.
setProperties
(
description
=
v_info
[
'description'
]
default_value
=
default_value
,
,
default_value
=
default_value
default_expr
=
default
[
'expression'
],
,
default_expr
=
default
[
'expression'
]
for_catalog
=
v_info
[
'for_catalog'
],
,
for_catalog
=
v_info
[
'for_catalog'
]
for_status
=
v_info
[
'for_status'
],
,
for_status
=
v_info
[
'for_status'
]
update_always
=
v_info
[
'update_always'
],
,
update_always
=
v_info
[
'update_always'
]
props
=
props
)
,
props
=
props
)
def
_initDCWorkflowStates
(
workflow
,
states
):
def
_initDCWorkflowStates
(
workflow
,
states
):
""" Initialize DCWorkflow states
""" Initialize DCWorkflow states
"""
"""
from
Products.DCWorkflow.States
import
StateDefinition
from
Products.DCWorkflow.States
import
StateDefinition
for
s_info
in
states
:
for
s_info
in
states
:
id
=
str
(
s_info
[
'state_id'
]
)
# no unicode!
id
=
str
(
s_info
[
'state_id'
]
)
# no unicode!
if
not
workflow
.
states
.
has_key
(
id
)
:
if
not
id
in
workflow
.
states
:
s
=
StateDefinition
(
id
)
s
=
StateDefinition
(
id
)
workflow
.
states
.
_setObject
(
id
,
s
)
workflow
.
states
.
_setObject
(
id
,
s
)
s
=
workflow
.
states
.
_getOb
(
id
)
s
=
workflow
.
states
.
_getOb
(
id
)
s
.
setProperties
(
title
=
s_info
[
'title'
]
s
.
setProperties
(
title
=
s_info
[
'title'
],
,
description
=
s_info
[
'description'
]
description
=
s_info
[
'description'
],
,
transitions
=
s_info
[
'transitions'
]
transitions
=
s_info
[
'transitions'
])
)
for
k
,
v
in
s_info
[
'permissions'
].
items
():
for
k
,
v
in
s_info
[
'permissions'
].
items
():
s
.
setPermission
(
k
,
isinstance
(
v
,
list
),
v
)
s
.
setPermission
(
k
,
isinstance
(
v
,
list
),
v
)
gmap
=
s
.
group_roles
=
PersistentMapping
()
gmap
=
s
.
group_roles
=
PersistentMapping
()
for
group_id
,
roles
in
s_info
[
'groups'
]:
for
group_id
,
roles
in
s_info
[
'groups'
]:
gmap
[
group_id
]
=
roles
gmap
[
group_id
]
=
roles
vmap
=
s
.
var_values
=
PersistentMapping
()
vmap
=
s
.
var_values
=
PersistentMapping
()
for
name
,
v_info
in
s_info
[
'variables'
].
items
():
for
name
,
v_info
in
s_info
[
'variables'
].
items
():
value
=
_convertVariableValue
(
v_info
[
'value'
],
v_info
[
'type'
])
value
=
_convertVariableValue
(
v_info
[
'value'
]
vmap
[
name
]
=
value
,
v_info
[
'type'
]
)
vmap
[
name
]
=
value
def
_initDCWorkflowTransitions
(
workflow
,
transitions
):
def
_initDCWorkflowTransitions
(
workflow
,
transitions
):
""" Initialize DCWorkflow transitions
""" Initialize DCWorkflow transitions
"""
"""
from
Products.DCWorkflow.Transitions
import
TransitionDefinition
from
Products.DCWorkflow.Transitions
import
TransitionDefinition
for
t_info
in
transitions
:
for
t_info
in
transitions
:
id
=
str
(
t_info
[
'transition_id'
]
)
# no unicode!
id
=
str
(
t_info
[
'transition_id'
]
)
# no unicode!
if
not
workflow
.
transitions
.
has_key
(
id
)
:
if
not
id
in
workflow
.
transitions
:
t
=
TransitionDefinition
(
id
)
t
=
TransitionDefinition
(
id
)
workflow
.
transitions
.
_setObject
(
id
,
t
)
workflow
.
transitions
.
_setObject
(
id
,
t
)
t
=
workflow
.
transitions
.
_getOb
(
id
)
t
=
workflow
.
transitions
.
_getOb
(
id
)
trigger_type
=
list
(
TRIGGER_TYPES
).
index
(
t_info
[
'trigger'
]
)
trigger_type
=
list
(
TRIGGER_TYPES
).
index
(
t_info
[
'trigger'
])
action
=
t_info
[
'action'
]
action
=
t_info
[
'action'
]
guard
=
t_info
[
'guard'
]
guard
=
t_info
[
'guard'
]
props
=
{
'guard_roles'
:
';'
.
join
(
guard
[
'roles'
]
)
props
=
{
'guard_roles'
:
';'
.
join
(
guard
[
'roles'
]),
,
'guard_permissions'
:
';'
.
join
(
guard
[
'permissions'
]
)
'guard_permissions'
:
';'
.
join
(
guard
[
'permissions'
]),
,
'guard_groups'
:
';'
.
join
(
guard
[
'groups'
]
)
'guard_groups'
:
';'
.
join
(
guard
[
'groups'
]),
,
'guard_expr'
:
guard
[
'expression'
]
'guard_expr'
:
guard
[
'expression'
]}
}
t
.
setProperties
(
title
=
t_info
[
'title'
],
t
.
setProperties
(
title
=
t_info
[
'title'
]
description
=
t_info
[
'description'
],
,
description
=
t_info
[
'description'
]
new_state_id
=
t_info
[
'new_state'
],
,
new_state_id
=
t_info
[
'new_state'
]
trigger_type
=
trigger_type
,
,
trigger_type
=
trigger_type
script_name
=
t_info
[
'before_script'
],
,
script_name
=
t_info
[
'before_script'
]
after_script_name
=
t_info
[
'after_script'
],
,
after_script_name
=
t_info
[
'after_script'
]
actbox_name
=
action
[
'name'
],
,
actbox_name
=
action
[
'name'
]
actbox_url
=
action
[
'url'
],
,
actbox_url
=
action
[
'url'
]
actbox_category
=
action
[
'category'
],
,
actbox_category
=
action
[
'category'
]
actbox_icon
=
action
.
get
(
'icon'
,
''
),
,
actbox_icon
=
action
.
get
(
'icon'
,
''
)
props
=
props
)
,
props
=
props
var_mapping
=
[
(
name
,
Expression
(
text
))
)
for
name
,
text
in
t_info
[
'variables'
].
items
()
]
var_mapping
=
[(
name
,
Expression
(
text
))
for
name
,
text
in
t_info
[
'variables'
].
items
()]
t
.
var_exprs
=
PersistentMapping
(
var_mapping
)
t
.
var_exprs
=
PersistentMapping
(
var_mapping
)
def
_initDCWorkflowWorklists
(
workflow
,
worklists
):
def
_initDCWorkflowWorklists
(
workflow
,
worklists
):
""" Initialize DCWorkflow worklists
""" Initialize DCWorkflow worklists
"""
"""
from
Products.DCWorkflow.Worklists
import
WorklistDefinition
from
Products.DCWorkflow.Worklists
import
WorklistDefinition
for
w_info
in
worklists
:
for
w_info
in
worklists
:
id
=
str
(
w_info
[
'worklist_id'
]
)
# no unicode!
id
=
str
(
w_info
[
'worklist_id'
]
)
# no unicode!
if
not
workflow
.
worklists
.
has_key
(
id
)
:
if
not
id
in
workflow
.
worklists
:
w
=
WorklistDefinition
(
id
)
w
=
WorklistDefinition
(
id
)
workflow
.
worklists
.
_setObject
(
id
,
w
)
workflow
.
worklists
.
_setObject
(
id
,
w
)
w
=
workflow
.
worklists
.
_getOb
(
id
)
w
=
workflow
.
worklists
.
_getOb
(
id
)
action
=
w_info
[
'action'
]
action
=
w_info
[
'action'
]
guard
=
w_info
[
'guard'
]
guard
=
w_info
[
'guard'
]
props
=
{
'guard_roles'
:
';'
.
join
(
guard
[
'roles'
]
)
props
=
{
'guard_roles'
:
';'
.
join
(
guard
[
'roles'
]),
,
'guard_permissions'
:
';'
.
join
(
guard
[
'permissions'
]
)
'guard_permissions'
:
';'
.
join
(
guard
[
'permissions'
]),
,
'guard_groups'
:
';'
.
join
(
guard
[
'groups'
]
)
'guard_groups'
:
';'
.
join
(
guard
[
'groups'
]),
,
'guard_expr'
:
guard
[
'expression'
]
'guard_expr'
:
guard
[
'expression'
]}
}
w
.
setProperties
(
description
=
w_info
[
'description'
]
w
.
setProperties
(
description
=
w_info
[
'description'
],
,
actbox_name
=
action
[
'name'
]
actbox_name
=
action
[
'name'
],
,
actbox_url
=
action
[
'url'
]
actbox_url
=
action
[
'url'
],
,
actbox_category
=
action
[
'category'
]
actbox_category
=
action
[
'category'
],
,
actbox_icon
=
action
.
get
(
'icon'
,
''
)
actbox_icon
=
action
.
get
(
'icon'
,
''
),
,
props
=
props
props
=
props
)
)
w
.
var_matches
=
PersistentMapping
()
w
.
var_matches
=
PersistentMapping
()
for
k
,
v
in
w_info
[
'match'
].
items
():
for
k
,
v
in
w_info
[
'match'
].
items
():
w
.
var_matches
[
str
(
k
)
]
=
tuple
(
[
str
(
x
)
for
x
in
v
]
)
w
.
var_matches
[
str
(
k
)]
=
tuple
([
str
(
x
)
for
x
in
v
])
def
_initDCWorkflowScripts
(
workflow
,
scripts
,
context
):
def
_initDCWorkflowScripts
(
workflow
,
scripts
,
context
):
""" Initialize DCWorkflow scripts
""" Initialize DCWorkflow scripts
"""
"""
for
s_info
in
scripts
:
for
s_info
in
scripts
:
id
=
str
(
s_info
[
'script_id'
]
)
# no unicode!
id
=
str
(
s_info
[
'script_id'
]
)
# no unicode!
meta_type
=
s_info
[
'meta_type'
]
meta_type
=
s_info
[
'meta_type'
]
filename
=
s_info
[
'filename'
]
filename
=
s_info
[
'filename'
]
file
=
''
file
=
''
if
filename
:
if
filename
:
file
=
context
.
readDataFile
(
filename
)
file
=
context
.
readDataFile
(
filename
)
if
meta_type
==
PythonScript
.
meta_type
:
if
meta_type
==
PythonScript
.
meta_type
:
script
=
PythonScript
(
id
)
script
=
PythonScript
(
id
)
script
.
write
(
file
)
script
.
write
(
file
)
elif
meta_type
==
ExternalMethod
.
meta_type
:
elif
meta_type
==
ExternalMethod
.
meta_type
:
script
=
ExternalMethod
(
id
script
=
ExternalMethod
(
id
,
''
,
s_info
[
'module'
],
,
''
s_info
[
'function'
])
,
s_info
[
'module'
]
,
s_info
[
'function'
]
)
elif
meta_type
==
DTMLMethod
.
meta_type
:
elif
meta_type
==
DTMLMethod
.
meta_type
:
script
=
DTMLMethod
(
file
,
__name__
=
id
)
script
=
DTMLMethod
(
file
,
__name__
=
id
)
else
:
else
:
for
mt
in
workflow
.
scripts
.
filtered_meta_types
():
for
mt
in
workflow
.
scripts
.
filtered_meta_types
():
if
mt
[
'name'
]
==
meta_type
:
if
mt
[
'name'
]
==
meta_type
:
if
hasattr
(
mt
[
'instance'
],
'write'
):
if
hasattr
(
mt
[
'instance'
],
'write'
):
script
=
mt
[
'instance'
](
id
)
script
=
mt
[
'instance'
](
id
)
script
.
write
(
file
)
script
.
write
(
file
)
...
@@ -1230,24 +1145,23 @@ def _initDCWorkflowScripts( workflow, scripts, context ):
...
@@ -1230,24 +1145,23 @@ def _initDCWorkflowScripts( workflow, scripts, context ):
script
=
mt
[
'instance'
](
file
,
__name__
=
id
)
script
=
mt
[
'instance'
](
file
,
__name__
=
id
)
break
break
else
:
else
:
raise
ValueError
,
'Invalid type: %s'
%
meta_type
raise
ValueError
(
'Invalid type: %s'
%
meta_type
)
if
workflow
.
scripts
.
has_key
(
id
)
:
if
id
in
workflow
.
scripts
:
workflow
.
scripts
.
_delObject
(
id
)
workflow
.
scripts
.
_delObject
(
id
)
workflow
.
scripts
.
_setObject
(
id
,
script
)
workflow
.
scripts
.
_setObject
(
id
,
script
)
#
#
# deprecated DOM parsing utilities
# deprecated DOM parsing utilities
#
#
_marker
=
object
()
_marker
=
object
()
def
_queryNodeAttribute
(
node
,
attr_name
,
default
,
encoding
=
'utf-8'
):
def
_queryNodeAttribute
(
node
,
attr_name
,
default
,
encoding
=
'utf-8'
):
""" Extract a string-valued attribute from node.
""" Extract a string-valued attribute from node.
o Return 'default' if the attribute is not present.
o Return 'default' if the attribute is not present.
"""
"""
attr_node
=
node
.
attributes
.
get
(
attr_name
,
_marker
)
attr_node
=
node
.
attributes
.
get
(
attr_name
,
_marker
)
if
attr_node
is
_marker
:
if
attr_node
is
_marker
:
return
default
return
default
...
@@ -1255,46 +1169,42 @@ def _queryNodeAttribute( node, attr_name, default, encoding='utf-8' ):
...
@@ -1255,46 +1169,42 @@ def _queryNodeAttribute( node, attr_name, default, encoding='utf-8' ):
value
=
attr_node
.
nodeValue
value
=
attr_node
.
nodeValue
if
encoding
is
not
None
:
if
encoding
is
not
None
:
value
=
value
.
encode
(
encoding
)
value
=
value
.
encode
(
encoding
)
return
value
return
value
def
_getNodeAttribute
(
node
,
attr_name
,
encoding
=
'utf-8'
):
def
_getNodeAttribute
(
node
,
attr_name
,
encoding
=
'utf-8'
):
""" Extract a string-valued attribute from node.
""" Extract a string-valued attribute from node.
"""
"""
value
=
_queryNodeAttribute
(
node
,
attr_name
,
_marker
,
encoding
)
value
=
_queryNodeAttribute
(
node
,
attr_name
,
_marker
,
encoding
)
if
value
is
_marker
:
if
value
is
_marker
:
raise
ValueError
,
'Invalid attribute: %s'
%
attr_name
raise
ValueError
(
'Invalid attribute: %s'
%
attr_name
)
return
value
return
value
def
_queryNodeAttributeBoolean
(
node
,
attr_name
,
default
):
def
_queryNodeAttributeBoolean
(
node
,
attr_name
,
default
):
""" Extract a string-valued attribute from node.
""" Extract a string-valued attribute from node.
o Return 'default' if the attribute is not present.
o Return 'default' if the attribute is not present.
"""
"""
attr_node
=
node
.
attributes
.
get
(
attr_name
,
_marker
)
attr_node
=
node
.
attributes
.
get
(
attr_name
,
_marker
)
if
attr_node
is
_marker
:
if
attr_node
is
_marker
:
return
default
return
default
value
=
node
.
attributes
[
attr_name
].
nodeValue
.
lower
()
value
=
node
.
attributes
[
attr_name
].
nodeValue
.
lower
()
return
value
in
(
'true'
,
'yes'
,
'1'
)
return
value
in
(
'true'
,
'yes'
,
'1'
)
def
_getNodeAttributeBoolean
(
node
,
attr_name
):
def
_getNodeAttributeBoolean
(
node
,
attr_name
):
""" Extract a string-valued attribute from node.
""" Extract a string-valued attribute from node.
"""
"""
value
=
node
.
attributes
[
attr_name
].
nodeValue
.
lower
()
value
=
node
.
attributes
[
attr_name
].
nodeValue
.
lower
()
return
value
in
(
'true'
,
'yes'
,
'1'
)
def
_coalesceTextNodeChildren
(
node
,
encoding
=
'utf-8'
):
return
value
in
(
'true'
,
'yes'
,
'1'
)
def
_coalesceTextNodeChildren
(
node
,
encoding
=
'utf-8'
):
""" Concatenate all childe text nodes into a single string.
""" Concatenate all childe text nodes into a single string.
"""
"""
from
xml.dom
import
Node
from
xml.dom
import
Node
...
@@ -1305,19 +1215,19 @@ def _coalesceTextNodeChildren( node, encoding='utf-8' ):
...
@@ -1305,19 +1215,19 @@ def _coalesceTextNodeChildren( node, encoding='utf-8' ):
while
child
is
not
None
:
while
child
is
not
None
:
if
child
.
nodeType
==
Node
.
TEXT_NODE
:
if
child
.
nodeType
==
Node
.
TEXT_NODE
:
fragments
.
append
(
child
.
nodeValue
)
fragments
.
append
(
child
.
nodeValue
)
child
=
child
.
nextSibling
child
=
child
.
nextSibling
joined
=
''
.
join
(
fragments
)
joined
=
''
.
join
(
fragments
)
if
encoding
is
not
None
:
if
encoding
is
not
None
:
joined
=
joined
.
encode
(
encoding
)
joined
=
joined
.
encode
(
encoding
)
return
''
.
join
(
[
line
.
lstrip
()
for
line
in
joined
.
splitlines
(
True
)
]
).
rstrip
()
return
''
.
join
([
line
.
lstrip
()
for
line
in
joined
.
splitlines
(
True
)
]).
rstrip
()
def
_extractDescriptionNode
(
parent
,
encoding
=
'utf-8'
):
def
_extractDescriptionNode
(
parent
,
encoding
=
'utf-8'
):
d_nodes
=
parent
.
getElementsByTagName
(
'description'
)
d_nodes
=
parent
.
getElementsByTagName
(
'description'
)
if
d_nodes
:
if
d_nodes
:
return
_coalesceTextNodeChildren
(
d_nodes
[
0
],
encoding
)
return
_coalesceTextNodeChildren
(
d_nodes
[
0
],
encoding
)
...
...
Products/DCWorkflow/utils.py
View file @
cd29c843
...
@@ -23,8 +23,8 @@ from zope.i18nmessageid import MessageFactory
...
@@ -23,8 +23,8 @@ from zope.i18nmessageid import MessageFactory
security
=
ModuleSecurityInfo
(
'Products.DCWorkflow.utils'
)
security
=
ModuleSecurityInfo
(
'Products.DCWorkflow.utils'
)
_dtmldir
=
os
.
path
.
join
(
package_home
(
globals
()
),
'dtml'
)
_dtmldir
=
os
.
path
.
join
(
package_home
(
globals
()),
'dtml'
)
_xmldir
=
os
.
path
.
join
(
package_home
(
globals
()
),
'xml'
)
_xmldir
=
os
.
path
.
join
(
package_home
(
globals
()),
'xml'
)
def
ac_inherited_permissions
(
ob
,
all
=
0
):
def
ac_inherited_permissions
(
ob
,
all
=
0
):
...
@@ -33,14 +33,15 @@ def ac_inherited_permissions(ob, all=0):
...
@@ -33,14 +33,15 @@ def ac_inherited_permissions(ob, all=0):
# an empty tuple as the second.
# an empty tuple as the second.
d
=
{}
d
=
{}
perms
=
getattr
(
ob
,
'__ac_permissions__'
,
())
perms
=
getattr
(
ob
,
'__ac_permissions__'
,
())
for
p
in
perms
:
d
[
p
[
0
]]
=
None
for
p
in
perms
:
d
[
p
[
0
]]
=
None
r
=
gather_permissions
(
ob
.
__class__
,
[],
d
)
r
=
gather_permissions
(
ob
.
__class__
,
[],
d
)
if
all
:
if
all
:
if
hasattr
(
ob
,
'_subobject_permissions'
):
if
hasattr
(
ob
,
'_subobject_permissions'
):
for
p
in
ob
.
_subobject_permissions
():
for
p
in
ob
.
_subobject_permissions
():
pname
=
p
[
0
]
pname
=
p
[
0
]
if
not
d
.
has_key
(
pname
)
:
if
not
pname
in
d
:
d
[
pname
]
=
1
d
[
pname
]
=
1
r
.
append
(
p
)
r
.
append
(
p
)
r
=
list
(
perms
)
+
r
r
=
list
(
perms
)
+
r
return
r
return
r
...
@@ -92,7 +93,7 @@ def modifyRolesForGroup(ob, group, grant_roles, managed_roles):
...
@@ -92,7 +93,7 @@ def modifyRolesForGroup(ob, group, grant_roles, managed_roles):
roles
.
remove
(
role
)
roles
.
remove
(
role
)
changed
=
1
changed
=
1
if
changed
:
if
changed
:
if
not
roles
and
local_roles
.
has_key
(
group
)
:
if
not
roles
and
group
in
local_roles
:
del
local_roles
[
group
]
del
local_roles
[
group
]
else
:
else
:
local_roles
[
group
]
=
roles
local_roles
[
group
]
=
roles
...
...
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