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

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