Commit 01686717 authored by Vincent Pelletier's avatar Vincent Pelletier

Fix coding style and get rid of intermediate variables.

parent 9e0e08b4
...@@ -58,10 +58,11 @@ def addWorkflowFactory(factory, id, title): ...@@ -58,10 +58,11 @@ def addWorkflowFactory(factory, id, title):
assert not _workflow_factories.get(id), ( assert not _workflow_factories.get(id), (
'Workflow factory with id %r already exists.' % id) 'Workflow factory with id %r already exists.' % id)
factory_info = dict(factory=factory, _workflow_factories[id] = {
id=id, 'factory': factory,
title=title) 'id': id,
_workflow_factories[id] = factory_info 'title': title,
}
# register with CMF 1 if it's still there # register with CMF 1 if it's still there
baseAddWorkflowFactory(factory, id, title) baseAddWorkflowFactory(factory, id, title)
...@@ -78,8 +79,8 @@ def _generateWorkflowConstructors(factory_info): ...@@ -78,8 +79,8 @@ def _generateWorkflowConstructors(factory_info):
workflow_factory_id = factory_info['id'] workflow_factory_id = factory_info['id']
workflow_factory_title = factory_info['title'] workflow_factory_title = factory_info['title']
# the method names (last url segments) # the method names (last url segments)
constructor_form_name=FACTORY_FORM_PREFIX + workflow_factory_id constructor_form_name = FACTORY_FORM_PREFIX + workflow_factory_id
constructor_action_name=FACTORY_ACTION_PREFIX + workflow_factory_id constructor_action_name = FACTORY_ACTION_PREFIX + workflow_factory_id
# The form # The form
def manage_addWorkflowForm(dispatcher, REQUEST, RESPONSE): def manage_addWorkflowForm(dispatcher, REQUEST, RESPONSE):
...@@ -102,9 +103,10 @@ def _generateWorkflowConstructors(factory_info): ...@@ -102,9 +103,10 @@ def _generateWorkflowConstructors(factory_info):
return workflow return workflow
# The constructors # The constructors
constructors = [(constructor_form_name, manage_addWorkflowForm), return [
(constructor_action_name, manage_addWorkflow)] (constructor_form_name, manage_addWorkflowForm),
return constructors (constructor_action_name, manage_addWorkflow),
]
def addWorkflowByType(container, workflow_factory_id, workflow_id): def addWorkflowByType(container, workflow_factory_id, workflow_id):
""" Add a workflow with name 'workflow_id' from factory identified by """ Add a workflow with name 'workflow_id' from factory identified by
...@@ -112,21 +114,20 @@ def addWorkflowByType(container, workflow_factory_id, workflow_id): ...@@ -112,21 +114,20 @@ def addWorkflowByType(container, workflow_factory_id, workflow_id):
""" """
# This functionality could be inside the generated manage_addWorkflow above, # This functionality could be inside the generated manage_addWorkflow above,
# but is placed here to be easily used directly from Python code. # but is placed here to be easily used directly from Python code.
workflow_factory = _workflow_factories[workflow_factory_id]['factory'] container._setObject(workflow_id,
workflow = workflow_factory(workflow_id) _workflow_factories[workflow_factory_id]['factory'](workflow_id))
container._setObject(workflow_id, workflow)
return aq_inner(container.restrictedTraverse(workflow_id)) return aq_inner(container.restrictedTraverse(workflow_id))
def registerWorkflowFactory(context, factory_info): def registerWorkflowFactory(context, factory_info):
""" Register a workflow factory as a Zope2 style object factory that is only """ Register a workflow factory as a Zope2 style object factory that is only
addable to portal_workflow""" addable to portal_workflow"""
constructors = _generateWorkflowConstructors(factory_info) context.registerClass(
permission = Permissions.ManagePortal DCWorkflowDefinition, # this class is only used here for its interfaces
context.registerClass(DCWorkflowDefinition, # this class is only used here for its interfaces meta_type=factory_info['title'],
meta_type=factory_info['title'], constructors=_generateWorkflowConstructors(factory_info),
constructors=constructors, permission=Permissions.ManagePortal,
permission=permission, visibility=None,
visibility=None) )
def registerAllWorkflowFactories(context): def registerAllWorkflowFactories(context):
"""register workflow factories during product initialization """register workflow factories during product initialization
......
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