# 
#
# Generated by dumpDCWorkflow.py written by Sebastien Bigaret
# Original workflow id/title: psc_release_workflow/PSC Release workflow
# Date: 2005/02/03 00:59:12.124 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.4 $"[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_release_workflow(wf):
    "..."
    wf.setProperties(title='PSC Release workflow')

    for s in ['pre-release', 'alpha', 'beta', 'release-candidate', 'final', 'hidden']:
        wf.states.addState(s)
    for t in ['release-alpha', 'release-beta', 'release-candidate', 'release-final', 'retract', 're-release', 'hide', 'unhide']:
        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, MODIFY, VIEW):
        wf.addManagedPermission(p)
        

    ## Initial State
    wf.states.setInitialState('pre-release')

    ## States initialization
    sdef = wf.states['pre-release']
    sdef.setProperties(title="""Unreleased""",
                       transitions=('release-alpha', 'release-beta', 'release-candidate', 'release-final', 'hide',))
    sdef.setPermission(ACCESS, 1, [])
    sdef.setPermission(VIEW, 1, [])
    sdef.setPermission(MODIFY, 1, [])
    
    sdef = wf.states['alpha']
    sdef.setProperties(title="""Alpha release""",
                       transitions=('re-release', 'release-beta', 'release-candidate', 'release-final', 'retract', 'hide',))
    sdef.setPermission(ACCESS, 1, [])
    sdef.setPermission(VIEW, 1, [])
    sdef.setPermission(MODIFY, 1, [])

    sdef = wf.states['beta']
    sdef.setProperties(title="""Beta release""",
                       transitions=('re-release', 'release-candidate', 'release-final', 'retract', 'hide',))
    sdef.setPermission(ACCESS, 1, [])
    sdef.setPermission(VIEW, 1, [])
    sdef.setPermission(MODIFY, 1, [])
    
    sdef = wf.states['release-candidate']
    sdef.setProperties(title="""Release candidate""",
                       transitions=('re-release', 'release-final', 'retract', 'hide',))
    sdef.setPermission(ACCESS, 1, [])
    sdef.setPermission(VIEW, 1, [])
    sdef.setPermission(MODIFY, 1, [])

    sdef = wf.states['final']
    sdef.setProperties(title="""Final release""",
                       transitions=('re-release', 'retract', 'hide',))
    sdef.setPermission(ACCESS, 1, [])
    sdef.setPermission(VIEW, 1, [])
    sdef.setPermission(MODIFY, 1, [])

    sdef = wf.states['hidden']
    sdef.setProperties(title="""Hidden""",
                       transitions=('unhide',))
    sdef.setPermission(ACCESS, 0, ['Owner', 'Manager',])
    sdef.setPermission(VIEW, 0, ['Owner', 'Manager',])
    sdef.setPermission(MODIFY, 1, [])

    ## Transitions initialization
    tdef = wf.transitions['release-alpha']
    tdef.setProperties(title="""Release alpha""",
                       new_state_id="""alpha""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""release_new_state""",
                       actbox_name="""Release alpha""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )
                       
    tdef = wf.transitions['release-beta']
    tdef.setProperties(title="""Release beta""",
                       new_state_id="""beta""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""release_new_state""",
                       actbox_name="""Release beta""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )

    tdef = wf.transitions['release-candidate']
    tdef.setProperties(title="""Release candidate""",
                       new_state_id="""release-candidate""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""release_new_state""",
                       actbox_name="""Release candidate""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )

    tdef = wf.transitions['release-final']
    tdef.setProperties(title="""Release final""",
                       new_state_id="""final""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""release_new_state""",
                       actbox_name="""Release final release""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )
                       
    tdef = wf.transitions['re-release']
    tdef.setProperties(title="""Re-release""",
                       new_state_id="""""",
                       trigger_type=1,
                       script_name="""re_release_state""",
                       after_script_name="""""",
                       actbox_name="""Re-release""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )

    tdef = wf.transitions['retract']
    tdef.setProperties(title="""Retract""",
                       new_state_id="""pre-release""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""release_new_state""",
                       actbox_name="""Retract release""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )
                       
    tdef = wf.transitions['hide']
    tdef.setProperties(title="""Hide""",
                       new_state_id="""hidden""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""release_new_state""",
                       actbox_name="""Hide release""",
                       actbox_url="""""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': MODIFY},
                       )
                       
    tdef = wf.transitions['unhide']
    tdef.setProperties(title="""Unhide""",
                       new_state_id="""pre-release""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""release_new_state""",
                       actbox_name="""Unhide release""",
                       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_release_workflow(id):
    "..."
    ob = DCWorkflowDefinition(id)
    setupPSC_release_workflow(ob)
    return ob

def install ():
    addWorkflowFactory(createPSC_release_workflow,
                       id='psc_release_workflow',
                       title='PSC Release workflow')

    
