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