Commit cd29c843 authored by 's avatar

code cleanup:

- replaced has_key
- replaced oldstyle errors
- PEP 8
parent 471e6021
##############################################################################
#
# Copyright (c) 2001 Zope Foundation and Contributors.
#
#
# 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.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
#
##############################################################################
""" A convenient base class for representing a container as a management tab.
"""
......@@ -51,27 +51,27 @@ class ContainerTab(Folder):
def _checkId(self, id, allow_dup=0):
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)
return Folder._checkId(self, id, allow_dup)
def _getOb(self, name, default=_marker):
mapping = self._mapping
if mapping.has_key(name):
if name in mapping:
res = mapping[name]
if hasattr(res, '__of__'):
res = res.__of__(self)
return res
else:
if default is _marker:
raise KeyError, name
raise KeyError(name)
return default
def __getattr__(self, name):
ob = self._mapping.get(name, None)
if ob is not None:
return ob
raise AttributeError, name
raise AttributeError(name)
def _setOb(self, name, value):
mapping = self._mapping
......@@ -84,13 +84,13 @@ class ContainerTab(Folder):
self._mapping = mapping # Trigger persistence.
def get(self, name, default=None):
if self._mapping.has_key(name):
if name in self._mapping:
return self[name]
else:
return default
def has_key(self, key):
return self._mapping.has_key(key)
return key in self._mapping
def objectIds(self, spec=None):
# spec is not important for now...
......
......@@ -45,7 +45,7 @@ from Products.DCWorkflow.WorkflowUIMixin import WorkflowUIMixin
def checkId(id):
res = bad_id(id)
if res != -1 and res is not None:
raise ValueError, 'Illegal ID'
raise ValueError('Illegal ID')
return 1
......@@ -88,8 +88,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
{'label': 'Worklists', 'action': 'worklists/manage_main'},
{'label': 'Scripts', 'action': 'scripts/manage_main'},
{'label': 'Permissions', 'action': 'manage_permissions'},
{'label': 'Groups', 'action': 'manage_groups'},
)
{'label': 'Groups', 'action': 'manage_groups'})
security = ClassSecurityInfo()
security.declareObjectProtected(ManagePortal)
......@@ -155,7 +154,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
status = self._getStatusOf(ob)
for id, vdef in self.variables.items():
if vdef.for_catalog:
if status.has_key(id):
if id in status:
value = status[id]
# Not set yet. Use a default.
......@@ -195,7 +194,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
'name': tdef.actbox_name % info,
'url': tdef.actbox_url % info,
'icon': tdef.actbox_icon % info,
'permissions': (), # Predetermined.
'permissions': (), # Predetermined.
'category': tdef.actbox_category,
'transition': tdef}))
res.sort()
......@@ -234,7 +233,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
'name': qdef.actbox_name % fmt_data,
'url': qdef.actbox_url % fmt_data,
'icon': qdef.actbox_icon % fmt_data,
'permissions': (), # Predetermined.
'permissions': (), # Predetermined.
'category': qdef.actbox_category}))
fmt_data._pop()
res.sort()
......@@ -303,7 +302,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
getSecurityManager(), self, ob):
return default
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]
# Not set yet. Use a default.
......@@ -332,7 +331,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
"""
try:
self._changeStateOf(ob, None)
except ( ObjectDeleted, ObjectMoved ):
except (ObjectDeleted, ObjectMoved):
# Swallow.
pass
......@@ -459,7 +458,8 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
raise WorkflowException(msg)
# 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.
if tdef is not None and tdef.script_name:
......@@ -475,20 +475,23 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
# Update variables.
state_values = new_sdef.var_values
if state_values is None: state_values = {}
if state_values is None:
state_values = {}
tdef_exprs = None
if tdef is not None: tdef_exprs = tdef.var_exprs
if tdef_exprs is None: tdef_exprs = {}
if tdef is not None:
tdef_exprs = tdef.var_exprs
if tdef_exprs is None:
tdef_exprs = {}
status = {}
for id, vdef in self.variables.items():
if not vdef.for_status:
continue
expr = None
if state_values.has_key(id):
if id in state_values:
value = state_values[id]
elif tdef_exprs.has_key(id):
elif id in tdef_exprs:
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
value = former_status[id]
else:
......@@ -525,7 +528,8 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
script(sci) # May throw an exception.
# 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.
if moved_exc is not None:
......
##############################################################################
#
# Copyright (c) 2001 Zope Foundation and Contributors.
#
#
# 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.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
#
##############################################################################
""" Expressions in a web-configurable workflow.
"""
......@@ -19,6 +19,7 @@ from Acquisition import aq_inner
from Acquisition import aq_parent
from App.class_init import InitializeClass
from DateTime.DateTime import DateTime
from MultiMapping import MultiMapping
from Products.PageTemplates.Expressions import getEngine
from Products.PageTemplates.Expressions import SecureModuleImporter
......@@ -28,10 +29,8 @@ from Products.CMFCore.WorkflowCore import ObjectDeleted
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):
"""Mapping with security declarations and limited method exposure.
Since it subclasses MultiMapping, this class can be used to wrap
......@@ -45,7 +44,8 @@ class SafeMapping(MultiMapping):
_pop = MultiMapping.pop
class StateChangeInfo:
class StateChangeInfo(object):
'''
Provides information for expressions and scripts.
'''
......@@ -83,7 +83,7 @@ class StateChangeInfo:
def __getitem__(self, name):
if name[:1] != '_' and hasattr(self, name):
return getattr(self, name)
raise KeyError, name
raise KeyError(name)
def getHistory(self):
wf = self.workflow
......@@ -126,7 +126,7 @@ def createExprContext(sci):
'folder': container,
'nothing': None,
'root': ob.getPhysicalRoot(),
'request': getattr( ob, 'REQUEST', None ),
'request': getattr(ob, 'REQUEST', None),
'modules': SecureModuleImporter,
'user': getSecurityManager().getUser(),
'state_change': sci,
......
......@@ -30,7 +30,8 @@ from Products.DCWorkflow.permissions import ManagePortal
from Products.DCWorkflow.utils import _dtmldir
class Guard (Persistent, Explicit):
class Guard(Persistent, Explicit):
permissions = ()
roles = ()
groups = ()
......@@ -68,10 +69,10 @@ class Guard (Persistent, Explicit):
if self.groups:
# Require at least one of the specified groups.
u = sm.getUser()
b = aq_base( u )
if hasattr( b, 'getGroupsInContext' ):
u_groups = u.getGroupsInContext( ob )
elif hasattr( b, 'getGroups' ):
b = aq_base(u)
if hasattr(b, 'getGroupsInContext'):
u_groups = u.getGroupsInContext(ob)
elif hasattr(b, 'getGroups'):
u_groups = u.getGroups()
else:
u_groups = ()
......
......@@ -21,7 +21,7 @@ from Products.DCWorkflow.ContainerTab import ContainerTab
from Products.DCWorkflow.permissions import ManagePortal
class Scripts (ContainerTab):
class Scripts(ContainerTab):
"""A container for workflow scripts"""
meta_type = 'Workflow Scripts'
......
......@@ -29,6 +29,7 @@ from Products.DCWorkflow.utils import _dtmldir
class StateDefinition(SimpleItem):
"""State definition"""
meta_type = 'Workflow State'
......@@ -37,8 +38,7 @@ class StateDefinition(SimpleItem):
{'label': 'Properties', 'action': 'manage_properties'},
{'label': 'Permissions', 'action': 'manage_permissions'},
{'label': 'Groups', 'action': 'manage_groups'},
{'label': 'Variables', 'action': 'manage_variables'},
)
{'label': 'Variables', 'action': 'manage_variables'})
title = ''
description = ''
......@@ -60,8 +60,8 @@ class StateDefinition(SimpleItem):
return aq_parent(aq_inner(aq_parent(aq_inner(self))))
def getTransitions(self):
return filter(self.getWorkflow().transitions.has_key,
self.transitions)
return [ t for t in self.transitions
if t in self.getWorkflow().transitions ]
def getTransitionTitle(self, tid):
t = self.getWorkflow().transitions.get(tid, None)
......@@ -88,13 +88,13 @@ class StateDefinition(SimpleItem):
if self.permission_roles:
roles = self.permission_roles.get(p, None)
if roles is None:
return {'acquired':1, 'roles':[]}
return {'acquired': 1, 'roles': []}
else:
if isinstance(roles, tuple):
acq = 0
else:
acq = 1
return {'acquired':acq, 'roles':list(roles)}
return {'acquired': acq, 'roles': list(roles)}
def getGroupInfo(self, group):
"""Returns the list of roles to be assigned to a group.
......@@ -112,7 +112,8 @@ class StateDefinition(SimpleItem):
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."""
self.title = str(title)
self.description = str(description)
......@@ -120,7 +121,6 @@ class StateDefinition(SimpleItem):
if REQUEST is not None:
return self.manage_properties(REQUEST, 'Properties changed.')
_variables_form = DTMLFile('state_variables', _dtmldir)
def manage_variables(self, REQUEST, manage_tabs_message=None):
......@@ -147,11 +147,11 @@ class StateDefinition(SimpleItem):
return wf_vars
ret = []
for vid in wf_vars:
if not self.var_values.has_key(vid):
if not vid in self.var_values:
ret.append(vid)
return ret
def addVariable(self,id,value,REQUEST=None):
def addVariable(self, id, value, REQUEST=None):
"""Add a WorkflowVariable to State."""
if self.var_values is None:
self.var_values = PersistentMapping()
......@@ -161,11 +161,11 @@ class StateDefinition(SimpleItem):
if REQUEST is not None:
return self.manage_variables(REQUEST, 'Variable added.')
def deleteVariables(self,ids=[],REQUEST=None):
def deleteVariables(self, ids=[], REQUEST=None):
"""Delete a WorkflowVariable from State."""
vv = self.var_values
for id in ids:
if vv.has_key(id):
if id in vv:
del vv[id]
if REQUEST is not None:
......@@ -184,8 +184,6 @@ class StateDefinition(SimpleItem):
vv[id] = str(REQUEST[fname])
return self.manage_variables(REQUEST, 'Variables changed.')
_permissions_form = DTMLFile('state_permissions', _dtmldir)
def manage_permissions(self, REQUEST, manage_tabs_message=None):
......@@ -254,6 +252,7 @@ InitializeClass(StateDefinition)
class States(ContainerTab):
"""A container for state definitions"""
meta_type = 'Workflow States'
......@@ -261,10 +260,9 @@ class States(ContainerTab):
security = ClassSecurityInfo()
security.declareObjectProtected(ManagePortal)
all_meta_types = ({'name':StateDefinition.meta_type,
'action':'addState',
'permission': ManagePortal,
},)
all_meta_types = ({'name': StateDefinition.meta_type,
'action': 'addState',
'permission': ManagePortal},)
_manage_states = DTMLFile('states', _dtmldir)
......@@ -297,7 +295,7 @@ class States(ContainerTab):
'''
if not id:
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 = str(id)
aq_parent(aq_inner(self)).initial_state = id
......
......@@ -31,7 +31,8 @@ TRIGGER_AUTOMATIC = 0
TRIGGER_USER_ACTION = 1
class TransitionDefinition (SimpleItem):
class TransitionDefinition(SimpleItem):
"""Transition definition"""
meta_type = 'Workflow Transition'
......@@ -54,8 +55,7 @@ class TransitionDefinition (SimpleItem):
manage_options = (
{'label': 'Properties', 'action': 'manage_properties'},
{'label': 'Variables', 'action': 'manage_variables'},
)
{'label': 'Variables', 'action': 'manage_variables'})
def __init__(self, id):
self.id = id
......@@ -152,7 +152,7 @@ class TransitionDefinition (SimpleItem):
else:
ret = []
for key in ve.keys():
ret.append((key,self.getVarExprText(key)))
ret.append((key, self.getVarExprText(key)))
return ret
def getWorkflowVariables(self):
......@@ -164,7 +164,7 @@ class TransitionDefinition (SimpleItem):
return wf_vars
ret = []
for vid in wf_vars:
if not self.var_exprs.has_key(vid):
if not vid in self.var_exprs:
ret.append(vid)
return ret
......@@ -183,12 +183,12 @@ class TransitionDefinition (SimpleItem):
if REQUEST is not None:
return self.manage_variables(REQUEST, 'Variable added.')
def deleteVariables(self,ids=[],REQUEST=None):
def deleteVariables(self, ids=[], REQUEST=None):
''' delete a WorkflowVariable from State
'''
ve = self.var_exprs
for id in ids:
if ve.has_key(id):
if id in ve:
del ve[id]
if REQUEST is not None:
......@@ -217,7 +217,8 @@ class TransitionDefinition (SimpleItem):
InitializeClass(TransitionDefinition)
class Transitions (ContainerTab):
class Transitions(ContainerTab):
"""A container for transition definitions"""
meta_type = 'Workflow Transitions'
......@@ -225,10 +226,9 @@ class Transitions (ContainerTab):
security = ClassSecurityInfo()
security.declareObjectProtected(ManagePortal)
all_meta_types = ({'name':TransitionDefinition.meta_type,
'action':'addTransition',
'permission': ManagePortal,
},)
all_meta_types = ({'name': TransitionDefinition.meta_type,
'action': 'addTransition',
'permission': ManagePortal},)
_manage_transitions = DTMLFile('transitions', _dtmldir)
......
##############################################################################
#
# Copyright (c) 2001 Zope Foundation and Contributors.
#
#
# 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.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
#
##############################################################################
""" Web-configurable workflow UI.
"""
......@@ -27,7 +27,8 @@ from Products.DCWorkflow.Guard import Guard
from Products.DCWorkflow.utils import _dtmldir
class WorkflowUIMixin:
class WorkflowUIMixin(object):
'''
'''
......@@ -39,7 +40,7 @@ class WorkflowUIMixin:
security.declareProtected(ManagePortal, 'setProperties')
@postonly
def setProperties(self, title, manager_bypass=0, props=None,
def setProperties(self, title, manager_bypass=0, props=None,
REQUEST=None, description=''):
"""Sets basic properties.
"""
......@@ -72,9 +73,9 @@ class WorkflowUIMixin:
"""Adds to the list of permissions to manage.
"""
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():
raise ValueError, 'Not a valid permission name:' + p
raise ValueError('Not a valid permission name:' + p)
self.permissions = self.permissions + (p,)
if REQUEST is not None:
return self.manage_permissions(
......@@ -111,7 +112,7 @@ class WorkflowUIMixin:
def getAvailableGroups(self):
"""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:
return ()
try:
......
......@@ -37,6 +37,7 @@ tales_re = re.compile(r'(\w+:)?(.*)')
class WorklistDefinition(SimpleItem):
"""Worklist definiton"""
meta_type = 'Worklist'
......@@ -52,9 +53,7 @@ class WorklistDefinition(SimpleItem):
actbox_category = 'global'
guard = None
manage_options = (
{'label': 'Properties', 'action': 'manage_properties'},
)
manage_options = ({'label': 'Properties', 'action': 'manage_properties'},)
def __init__(self, id):
self.id = id
......@@ -141,7 +140,7 @@ class WorklistDefinition(SimpleItem):
self.var_matches[key] = tuple(v)
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]
self.actbox_name = str(actbox_name)
self.actbox_url = str(actbox_url)
......@@ -189,6 +188,7 @@ InitializeClass(WorklistDefinition)
class Worklists(ContainerTab):
"""A container for worklist definitions"""
meta_type = 'Worklists'
......@@ -196,10 +196,9 @@ class Worklists(ContainerTab):
security = ClassSecurityInfo()
security.declareObjectProtected(ManagePortal)
all_meta_types = ({'name':WorklistDefinition.meta_type,
'action':'addWorklist',
'permission': ManagePortal,
},)
all_meta_types = ({'name': WorklistDefinition.meta_type,
'action': 'addWorklist',
'permission': ManagePortal},)
_manage_worklists = DTMLFile('worklists', _dtmldir)
......
This diff is collapsed.
......@@ -23,8 +23,8 @@ from zope.i18nmessageid import MessageFactory
security = ModuleSecurityInfo('Products.DCWorkflow.utils')
_dtmldir = os.path.join( package_home( globals() ), 'dtml' )
_xmldir = os.path.join( package_home( globals() ), 'xml' )
_dtmldir = os.path.join(package_home(globals()), 'dtml')
_xmldir = os.path.join(package_home(globals()), 'xml')
def ac_inherited_permissions(ob, all=0):
......@@ -33,14 +33,15 @@ def ac_inherited_permissions(ob, all=0):
# an empty tuple as the second.
d = {}
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)
if all:
if hasattr(ob, '_subobject_permissions'):
for p in ob._subobject_permissions():
pname=p[0]
if not d.has_key(pname):
d[pname]=1
pname = p[0]
if not pname in d:
d[pname] = 1
r.append(p)
r = list(perms) + r
return r
......@@ -92,7 +93,7 @@ def modifyRolesForGroup(ob, group, grant_roles, managed_roles):
roles.remove(role)
changed = 1
if changed:
if not roles and local_roles.has_key(group):
if not roles and group in local_roles:
del local_roles[group]
else:
local_roles[group] = roles
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment