# 
#
# Generated by dumpDCWorkflow.py written by Sebastien Bigaret
# Original workflow id/title: psc_improvementproposal_workflow/PSC Improvement Proposal workflow
# Date: 2005/02/03 00:53:10.865 GMT
#
# WARNING: this dumps does NOT contain any scripts you might have added to
# the workflow, IT IS YOUR RESPONSABILITY TO MAKE BACKUPS FOR THESE SCRIPTS.
#
# No script detected in this workflow
# 
"""
Programmatically creates a workflow type
"""
__version__ = "$Revision: 1.3 $"[11:-2]

from Products.CMFCore.WorkflowTool import addWorkflowFactory

from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition

from Products.CMFCore import permissions

ACCESS = permissions.AccessContentsInformation
VIEW   = permissions.View
MODIFY = permissions.ModifyPortalContent
ADD    = permissions.AddPortalContent

def setupPSC_improvementproposal_workflow(wf):
    "..."
    wf.setProperties(title='PSC Improvement Proposal workflow')

    for s in ['draft', 'being-discussed', 'in-progress', 'rejected', 'deferred', 'ready-for-merge', 'completed']:
        wf.states.addState(s)
    for t in ['propose', 're-draft', 'accept', 'defer', 'begin', 're-work', 'complete', 're-merge', 'merge', 'reject', 're-discuss']:
        wf.transitions.addTransition(t)
    for v in ['action', 'review_history', 'actor', 'comments', 'time']:
        wf.variables.addVariable(v)
    for l in ['reviewer_queue']:
        wf.worklists.addWorklist(l)
    for p in (ACCESS, VIEW, MODIFY):
        wf.addManagedPermission(p)
        

    ## Initial State
    wf.states.setInitialState('draft')

    ## States initialization

    # All roles are acquired from parent, since we are not controlling
    # access with these states, only the state of the proposal. The same
    # users who can view the project can view the proposals   
    
    sdef = wf.states['draft']
    sdef.setProperties(title="""Draft""",
                       transitions=('propose',))
    sdef.setPermission(ACCESS, 1, [])
    sdef.setPermission(MODIFY, 1, [])
    sdef.setPermission(VIEW, 1, [])
    
    sdef = wf.states['in-progress']
    sdef.setProperties(title="""In progress""",
                       transitions=('complete', 'defer', 're-discuss', 'reject'))
    sdef.setPermission(ACCESS, 1, [])
    sdef.setPermission(MODIFY, 1, [])
    sdef.setPermission(VIEW, 1, [])

    sdef = wf.states['completed']
    sdef.setProperties(title="""Completed and merged""",
                       transitions=('re-merge',))
    sdef.setPermission(ACCESS, 1, [])
    sdef.setPermission(MODIFY, 1, [])
    sdef.setPermission(VIEW, 1, [])

    sdef = wf.states['rejected']
    sdef.setProperties(title="""Rejected""",
                       transitions=('re-draft',))
    sdef.setPermission(ACCESS, 1, [])
    sdef.setPermission(MODIFY, 1, [])
    sdef.setPermission(VIEW, 1, [])

    sdef = wf.states['deferred']
    sdef.setProperties(title="""Deferred""",
                       transitions=('begin', 're-draft', 'reject'))
    sdef.setPermission(ACCESS, 1, [])
    sdef.setPermission(MODIFY, 1, [])
    sdef.setPermission(VIEW, 1, [])

    sdef = wf.states['ready-for-merge']
    sdef.setProperties(title="""Ready for merge""",
                       transitions=('defer', 'merge', 're-work', 'reject'))
    sdef.setPermission(ACCESS, 1, [])
    sdef.setPermission(MODIFY, 1, [])
    sdef.setPermission(VIEW, 1, [])

    sdef = wf.states['being-discussed']
    sdef.setProperties(title="""Being discussed""",
                       transitions=('begin', 'defer', 'reject', 're-draft'))
    sdef.setPermission(ACCESS, 1, [])
    sdef.setPermission(MODIFY, 1, [])
    sdef.setPermission(VIEW, 1, [])


    ## Transitions initialization
    tdef = wf.transitions['propose']
    tdef.setProperties(title="""Propose""",
                       new_state_id="""being-discussed""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Propose""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )
                       
    tdef = wf.transitions['re-draft']
    tdef.setProperties(title="""Re-draft""",
                       new_state_id="""draft""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Re-draft""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )
    
    tdef = wf.transitions['defer']
    tdef.setProperties(title="""Defer work on this proposal""",
                       new_state_id="""deferred""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Defer work""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )

    tdef = wf.transitions['begin']
    tdef.setProperties(title="""Begin proposed work""",
                       new_state_id="""in-progress""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Begin work""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )

    tdef = wf.transitions['re-work']
    tdef.setProperties(title="""Return to in-progress stage""",
                       new_state_id="""in-progress""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Re-work""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )

    tdef = wf.transitions['complete']
    tdef.setProperties(title="""Complete proposed work""",
                       new_state_id="""ready-for-merge""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Complete work""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )

    tdef = wf.transitions['re-merge']
    tdef.setProperties(title="""Return to ready-for-merge stage""",
                       new_state_id="""ready-for-merge""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Un-merge""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )

    tdef = wf.transitions['merge']
    tdef.setProperties(title="""Merge changes from this proposal""",
                       new_state_id="""completed""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Merge changes""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )

    tdef = wf.transitions['reject']
    tdef.setProperties(title="""Reject this proposal""",
                       new_state_id="""rejected""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Reject proposal""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )

    tdef = wf.transitions['re-discuss']
    tdef.setProperties(title="""Return to discussion stage""",
                       new_state_id="""being-discussed""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Re-discuss""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )

    ## State Variable
    wf.variables.setStateVar('review_state')

    ## Variables initialization
    vdef = wf.variables['action']
    vdef.setProperties(description="""The last transition""",
                       default_value="""""",
                       default_expr="""transition/getId|nothing""",
                       for_catalog=0,
                       for_status=1,
                       update_always=1,
                       props=None)

    vdef = wf.variables['review_history']
    vdef.setProperties(description="""Provides access to workflow history""",
                       default_value="""""",
                       default_expr="""state_change/getHistory""",
                       for_catalog=0,
                       for_status=0,
                       update_always=0,
                       props={'guard_permissions': 'Request review; Review portal content'})

    vdef = wf.variables['actor']
    vdef.setProperties(description="""The ID of the user who performed the last transition""",
                       default_value="""""",
                       default_expr="""user/getId""",
                       for_catalog=0,
                       for_status=1,
                       update_always=1,
                       props=None)

    vdef = wf.variables['comments']
    vdef.setProperties(description="""Comments about the last transition""",
                       default_value="""""",
                       default_expr="""python:state_change.kwargs.get('comment', '')""",
                       for_catalog=0,
                       for_status=1,
                       update_always=1,
                       props=None)

    vdef = wf.variables['time']
    vdef.setProperties(description="""Time of the last transition""",
                       default_value="""""",
                       default_expr="""state_change/getDateTime""",
                       for_catalog=0,
                       for_status=1,
                       update_always=1,
                       props=None)

    ## Worklists Initialization
    ldef = wf.worklists['reviewer_queue']
    ldef.setProperties(description="""Reviewer tasks""",
                       actbox_name="""Pending (%(count)d)""",
                       actbox_url="""%(portal_url)s/search?review_state=pending""",
                       actbox_category="""global""",
                       props={'guard_permissions': 'Review portal content', 'var_match_review_state': 'pending'})


def createPSC_improvementproposal_workflow(id):
    "..."
    ob = DCWorkflowDefinition(id)
    setupPSC_improvementproposal_workflow(ob)
    return ob

def install ():
    addWorkflowFactory(createPSC_improvementproposal_workflow,
                       id='psc_improvementproposal_workflow',
                       title='PSC Improvement Proposal workflow')

    
