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

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

Split workflow components (general use stuff goes to w.s.workflow), add some convenience stuff, ...)

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