source: main/waeup.sirp/trunk/src/waeup/sirp/applicants/workflow.py @ 7155

Last change on this file since 7155 was 7063, checked in by uli, 13 years ago

Merge changes from branch ulif-extimgstore back into trunk.
Beside external image storage also waeupdocs should work again.

  • Property svn:keywords set to Id
File size: 3.9 KB
RevLine 
[6295]1"""Workflow for applicants.
2"""
3import grok
[6353]4from hurry.workflow.workflow import Transition, WorkflowState, NullCondition
5from hurry.workflow.interfaces import IWorkflowState, IWorkflowTransitionEvent
[6295]6from waeup.sirp.applicants.interfaces import IApplicantBaseData
[6353]7from waeup.sirp.interfaces import IObjectHistory, IWAeUPWorkflowInfo
[6355]8from waeup.sirp.workflow import WAeUPWorkflow, WAeUPWorkflowInfo
[6644]9from waeup.sirp.utils.helpers import get_current_principal
[6295]10
11INITIALIZED = 'initialized'
12STARTED = 'started'
13SUBMITTED = 'submitted'
14ADMITTED = 'admitted'
15NOT_ADMITTED = 'not admitted'
16CREATED = 'created'
17
[6354]18APPLICATION_TRANSITIONS = (
[6353]19    Transition(
[6295]20        transition_id = 'init',
[6306]21        title = 'Initialize application',
[6295]22        source = None,
23        condition = NullCondition,
[6471]24        msg = 'Application initialized',
[6353]25        destination = INITIALIZED),
[6295]26
[6353]27    Transition(
[6295]28        transition_id = 'start',
[6300]29        title = 'Start application',
[6471]30        msg = 'Application started',
[6295]31        source = INITIALIZED,
[6353]32        destination = STARTED),
[6295]33
[6353]34    Transition(
[6295]35        transition_id = 'submit',
[6307]36        title = 'Submit application',
[6471]37        msg = 'Application submitted',
[6295]38        source = STARTED,
[6353]39        destination = SUBMITTED),
[6295]40
[6353]41    Transition(
[6295]42        transition_id = 'admit',
[6300]43        title = 'Admit applicant',
[6471]44        msg = 'Applicant admitted',
[6295]45        source = SUBMITTED,
[6353]46        destination = ADMITTED),
[6295]47
[6353]48    Transition(
[6300]49        transition_id = 'refuse1',
50        title = 'Refuse application',
[6471]51        msg = 'Application refused',
[6295]52        source = SUBMITTED,
[6353]53        destination = NOT_ADMITTED),
[6295]54
[6353]55    Transition(
[6300]56        transition_id = 'refuse2',
57        title = 'Refuse application',
[6471]58        msg = 'Application refused',
[6300]59        source = ADMITTED,
[6353]60        destination = NOT_ADMITTED),
[6300]61
[6353]62    Transition(
[6295]63        transition_id = 'create',
[6307]64        title = 'Create student record',
[6471]65        msg = 'Student record created',
[6295]66        source = ADMITTED,
[6353]67        destination = CREATED),
[6295]68
[6353]69    Transition(
[6300]70        transition_id = 'reset1',
71        title = 'Reset application',
[6471]72        msg = 'Application reset',
[6300]73        source = SUBMITTED,
[6353]74        destination = STARTED),
[6295]75
[6353]76    Transition(
[6300]77        transition_id = 'reset2',
78        title = 'Reset application',
[6471]79        msg = 'Application reset',
[6300]80        source = ADMITTED,
[6353]81        destination = STARTED),
[6300]82
[6353]83    Transition(
[6300]84        transition_id = 'reset3',
85        title = 'Reset application',
[6471]86        msg = 'Application reset',
[6300]87        source = NOT_ADMITTED,
[6353]88        destination = STARTED),
[6300]89
[6353]90    Transition(
[6300]91        transition_id = 'reset4',
92        title = 'Reset application',
[6471]93        msg = 'Application reset',
[6300]94        source = CREATED,
[6353]95        destination = STARTED),
96    )
[6300]97
[6354]98application_workflow = WAeUPWorkflow(APPLICATION_TRANSITIONS)
[6295]99
[6349]100class ApplicationWorkflowState(WorkflowState, grok.Adapter):
[6295]101    """An adapter to adapt Applicant objects to workflow states.
102    """
103    grok.context(IApplicantBaseData)
104    grok.provides(IWorkflowState)
[6316]105
[6349]106    state_key = 'wf.application.state'
107    state_id = 'wf.application.id'
108
[6353]109class ApplicationWorkflowInfo(WAeUPWorkflowInfo, grok.Adapter):
[6295]110    """Adapter to adapt Applicant objects to workflow info objects.
111    """
112    grok.context(IApplicantBaseData)
[6353]113    grok.provides(IWAeUPWorkflowInfo)
[6318]114
[6349]115    def __init__(self, context):
116        self.context = context
117        self.wf = application_workflow
[6318]118
119@grok.subscribe(IApplicantBaseData, IWorkflowTransitionEvent)
120def handle_applicant_transition_event(obj, event):
[6471]121    """Append message to applicant history when transition happened.
[6318]122    """
[6471]123    msg = '%s' % event.transition.user_data['msg']
[6339]124    history = IObjectHistory(obj)
125    history.addMessage(msg)
[6644]126    # In some tests we don't have a an applicants root or a user
127    try:
128        user = get_current_principal()
129        applicants_root = grok.getSite()['applicants']
130        applicants_root.logger.info('%s - %s - %s' % (user.id,obj.access_code,msg))
131    except (TypeError, AttributeError):
132        pass
[6318]133    return
Note: See TracBrowser for help on using the repository browser.