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

Last change on this file since 6550 was 6471, checked in by Henrik Bettermann, 13 years ago

Produce more user friendly and shorter object history messages.

  • Property svn:keywords set to Id
File size: 3.6 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 initialized',
25        destination = INITIALIZED),
26
27    Transition(
28        transition_id = 'start',
29        title = 'Start application',
30        msg = 'Application started',
31        source = INITIALIZED,
32        destination = STARTED),
33
34    Transition(
35        transition_id = 'submit',
36        title = 'Submit application',
37        msg = 'Application 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 reset',
73        source = SUBMITTED,
74        destination = STARTED),
75
76    Transition(
77        transition_id = 'reset2',
78        title = 'Reset application',
79        msg = 'Application reset',
80        source = ADMITTED,
81        destination = STARTED),
82
83    Transition(
84        transition_id = 'reset3',
85        title = 'Reset application',
86        msg = 'Application reset',
87        source = NOT_ADMITTED,
88        destination = STARTED),
89
90    Transition(
91        transition_id = 'reset4',
92        title = 'Reset application',
93        msg = 'Application 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 history when transition happened.
122    """
123    msg = '%s' % event.transition.user_data['msg']
124    history = IObjectHistory(obj)
125    history.addMessage(msg)
126    return
Note: See TracBrowser for help on using the repository browser.