source: main/waeup.sirp/trunk/src/waeup/sirp/students/workflow.py @ 6830

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

Application is only allowed between start and end time. Show dates on login page and logout applicants if current time exceeds these limits.

  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1"""Workflow for students.
2"""
3import grok
4from hurry.workflow.workflow import Transition, WorkflowState, NullCondition
5from hurry.workflow.interfaces import IWorkflowState, IWorkflowTransitionEvent
6from waeup.sirp.interfaces import IObjectHistory, IWAeUPWorkflowInfo
7from waeup.sirp.workflow import WAeUPWorkflow, WAeUPWorkflowInfo
8from waeup.sirp.utils.helpers import get_current_principal
9from waeup.sirp.students.interfaces import IStudent
10from waeup.sirp.students.utils import set_returning_data
11
12CREATED = 'created'
13ADMITTED = 'admitted'
14CLEARANCE = 'clearance started'
15REQUESTED = 'clearance requested'
16CLEARED = 'cleared'
17PAID = 'school fee paid'
18RETURNING = 'returning'
19REGISTERED = 'courses registered'
20VALIDATED = 'courses validated'
21
22REGISTRATION_TRANSITIONS = (
23    Transition(
24        transition_id = 'create',
25        title = 'Create student',
26        source = None,
27        condition = NullCondition,
28        msg = 'Student record created',
29        destination = CREATED),
30
31    Transition(
32        transition_id = 'admit',
33        title = 'Admit student',
34        msg = 'Student admitted',
35        source = CREATED,
36        destination = ADMITTED),
37
38    Transition(
39        transition_id = 'reset1',
40        title = 'Reset student',
41        msg = 'Student record reset',
42        source = ADMITTED,
43        destination = CREATED),
44
45    Transition(
46        transition_id = 'start_clearance',
47        title = 'Start clearance',
48        msg = 'Clearance started',
49        source = ADMITTED,
50        destination = CLEARANCE),
51
52    Transition(
53        transition_id = 'reset2',
54        title = 'Reset to admitted',
55        msg = 'Student record reset to admitted',
56        source = CLEARANCE,
57        destination = ADMITTED),
58
59    Transition(
60        transition_id = 'request_clearance',
61        title = 'Request clearance',
62        msg = 'Clearance requested',
63        source = CLEARANCE,
64        destination = REQUESTED),
65
66    Transition(
67        transition_id = 'reset3',
68        title = 'Reset to clearance',
69        msg = 'Student record reset to clearance',
70        source = REQUESTED,
71        destination = CLEARANCE),
72
73    Transition(
74        transition_id = 'clear',
75        title = 'Clear student',
76        msg = 'Cleared',
77        source = REQUESTED,
78        destination = CLEARED),
79
80    Transition(
81        transition_id = 'reset4',
82        title = 'Reset to clearance',
83        msg = 'Student record reset to clearance',
84        source = CLEARED,
85        destination = CLEARANCE),
86
87    Transition(
88        transition_id = 'pay_first_school_fee',
89        title = 'Pay school fee',
90        msg = 'School fee paid',
91        source = CLEARED,
92        destination = PAID),
93
94    Transition(
95        transition_id = 'reset5',
96        title = 'Reset to cleared',
97        msg = 'Student record reset to cleared',
98        source = PAID,
99        destination = CLEARED),
100
101    Transition(
102        transition_id = 'pay_school_fee',
103        title = 'Pay school fee',
104        msg = 'School fee paid',
105        source = RETURNING,
106        destination = PAID),
107
108    Transition(
109        transition_id = 'reset6',
110        title = 'Reset to returning',
111        msg = 'Student record reset to returning',
112        source = PAID,
113        destination = RETURNING),
114
115    Transition(
116        transition_id = 'register_courses',
117        title = 'Register courses',
118        msg = 'Courses registered',
119        source = PAID,
120        destination = REGISTERED),
121
122    Transition(
123        transition_id = 'reset7',
124        title = 'Reset to paid',
125        msg = 'Student record reset to paid',
126        source = REGISTERED,
127        destination = PAID),
128
129    Transition(
130        transition_id = 'validate_courses',
131        title = 'Validate courses',
132        msg = 'Courses validated',
133        source = REGISTERED,
134        destination = VALIDATED),
135
136    Transition(
137        transition_id = 'reset8',
138        title = 'Reset to paid',
139        msg = 'Student record reset to paid',
140        source = VALIDATED,
141        destination = PAID),
142
143    Transition(
144        transition_id = 'return',
145        title = 'Return',
146        msg = 'Returned',
147        source = VALIDATED,
148        destination = RETURNING),
149
150    Transition(
151        transition_id = 'reset9',
152        title = 'Reset to validated',
153        msg = 'Student record reset to validated',
154        source = RETURNING,
155        destination = VALIDATED),
156    )
157
158LOCK_CLEARANCE_TRANS = ('reset2', 'request_clearance')
159UNLOCK_CLEARANCE_TRANS = ('reset3', 'reset4', 'start_clearance')
160
161registration_workflow = WAeUPWorkflow(REGISTRATION_TRANSITIONS)
162
163class RegistrationWorkflowState(WorkflowState, grok.Adapter):
164    """An adapter to adapt Student objects to workflow states.
165    """
166    grok.context(IStudent)
167    grok.provides(IWorkflowState)
168
169    state_key = 'wf.registration.state'
170    state_id = 'wf.registration.id'
171
172class RegistrationWorkflowInfo(WAeUPWorkflowInfo, grok.Adapter):
173    """Adapter to adapt Student objects to workflow info objects.
174    """
175    grok.context(IStudent)
176    grok.provides(IWAeUPWorkflowInfo)
177
178    def __init__(self, context):
179        self.context = context
180        self.wf = registration_workflow
181
182@grok.subscribe(IStudent, IWorkflowTransitionEvent)
183def handle_student_transition_event(obj, event):
184    """Append message to student history and log file when transition happened.
185    """
186    msg = '%s' % event.transition.user_data['msg']
187    history = IObjectHistory(obj)
188    history.addMessage(msg)
189    if event.transition.transition_id in LOCK_CLEARANCE_TRANS:
190        obj.clearance_locked = True
191    if event.transition.transition_id in UNLOCK_CLEARANCE_TRANS:
192        obj.clearance_locked = False
193    # Student data don't change after first-time payment
194    if event.transition.transition_id == 'pay_first_school_fee':
195        pass
196    # School fee payment of returning students triggers the change of
197    # current session, current level, and current verdict
198    if event.transition.transition_id == 'pay_school_fee':
199        set_returning_data(obj)
200    # In some tests we don't have a students container or a user
201    try:
202        user = get_current_principal()
203        students_container = grok.getSite()['students']
204        students_container.logger.info('%s - %s - %s' % (user.id,obj.student_id,msg))
205    except (TypeError, AttributeError):
206        pass
207    return
Note: See TracBrowser for help on using the repository browser.