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

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

Add fields email and phone which can be edited via the StudentBaseEditFormPage?. email, phone and passport picture are required for starting clearance.

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