source: main/waeup.kofa/trunk/src/waeup/kofa/students/workflow.py @ 14287

Last change on this file since 14287 was 13610, checked in by Henrik Bettermann, 9 years ago

Add button and view which allow students to unregister their
current course list unless the courses have not been validated.

  • Property svn:keywords set to Id
File size: 8.9 KB
Line 
1"""Workflow for students.
2"""
3import grok
4from datetime import datetime
5from zope.component import getUtility
6from hurry.workflow.workflow import Transition, WorkflowState, NullCondition
7from hurry.workflow.interfaces import IWorkflowState, IWorkflowTransitionEvent
8from waeup.kofa.interfaces import (
9    IObjectHistory, IKofaWorkflowInfo, IKofaUtils,
10    CREATED, ADMITTED, CLEARANCE, REQUESTED, CLEARED, PAID, RETURNING,
11    REGISTERED, VALIDATED, GRADUATED, TRANSCRIPT)
12from waeup.kofa.interfaces import MessageFactory as _
13from waeup.kofa.workflow import KofaWorkflow, KofaWorkflowInfo
14from waeup.kofa.students.interfaces import IStudent, IStudentsUtils
15from waeup.kofa.utils.helpers import get_current_principal
16
17
18IMPORTABLE_STATES = (ADMITTED, CLEARANCE, REQUESTED, CLEARED, PAID, RETURNING,
19    REGISTERED, VALIDATED, GRADUATED)
20
21FORBIDDEN_POSTGRAD_STATES = (RETURNING, REGISTERED, VALIDATED)
22
23REGISTRATION_TRANSITIONS = (
24    Transition(
25        transition_id = 'create',
26        title = _('Create student'),
27        source = None,
28        condition = NullCondition,
29        msg = _('Record created'),
30        destination = CREATED),
31
32    Transition(
33        transition_id = 'admit',
34        title = _('Admit student'),
35        msg = _('Admitted'),
36        source = CREATED,
37        destination = ADMITTED),
38
39    Transition(
40        transition_id = 'reset1',
41        title = _('Reset student'),
42        msg = _('Reset to initial state'),
43        source = ADMITTED,
44        destination = CREATED),
45
46    Transition(
47        transition_id = 'start_clearance',
48        title = _('Start clearance'),
49        msg = _('Clearance started'),
50        source = ADMITTED,
51        destination = CLEARANCE),
52
53    Transition(
54        transition_id = 'reset2',
55        title = _('Reset to admitted'),
56        msg = _("Reset to 'admitted'"),
57        source = CLEARANCE,
58        destination = ADMITTED),
59
60    Transition(
61        transition_id = 'request_clearance',
62        title = _('Request clearance'),
63        msg = _('Clearance requested'),
64        source = CLEARANCE,
65        destination = REQUESTED),
66
67    Transition(
68        transition_id = 'reset3',
69        title = _('Reset to clearance started'),
70        msg = _("Reset to 'clearance started'"),
71        source = REQUESTED,
72        destination = CLEARANCE),
73
74    Transition(
75        transition_id = 'clear',
76        title = _('Clear student'),
77        msg = _('Cleared'),
78        source = REQUESTED,
79        destination = CLEARED),
80
81    Transition(
82        transition_id = 'reset4',
83        title = _('Reset to clearance started'),
84        msg = _("Reset to 'clearance started'"),
85        source = CLEARED,
86        destination = CLEARANCE),
87
88    Transition(
89        transition_id = 'pay_first_school_fee',
90        title = _('Pay school fee'),
91        msg = _('First school fee payment made'),
92        source = CLEARED,
93        destination = PAID),
94
95    Transition(
96        transition_id = 'approve_first_school_fee',
97        title = _('Approve payment'),
98        msg = _('First school fee payment approved'),
99        source = CLEARED,
100        destination = PAID),
101
102    Transition(
103        transition_id = 'reset5',
104        title = _('Reset to cleared'),
105        msg = _("Reset to 'cleared'"),
106        source = PAID,
107        destination = CLEARED),
108
109    Transition(
110        transition_id = 'pay_school_fee',
111        title = _('Pay school fee'),
112        msg = _('School fee payment made'),
113        source = RETURNING,
114        destination = PAID),
115
116    Transition(
117        transition_id = 'pay_pg_fee',
118        title = _('Pay PG school fee'),
119        msg = _('PG school fee payment made'),
120        source = PAID,
121        destination = PAID),
122
123    Transition(
124        transition_id = 'approve_school_fee',
125        title = _('Approve school fee payment'),
126        msg = _('School fee payment approved'),
127        source = RETURNING,
128        destination = PAID),
129
130    Transition(
131        transition_id = 'approve_pg_fee',
132        title = _('Approve PG school fee payment'),
133        msg = _('PG school fee payment approved'),
134        source = PAID,
135        destination = PAID),
136
137    Transition(
138        transition_id = 'reset6',
139        title = _('Reset to returning'),
140        msg = _("Reset to 'returning'"),
141        source = PAID,
142        destination = RETURNING),
143
144    Transition(
145        transition_id = 'register_courses',
146        title = _('Register courses'),
147        msg = _('Courses registered'),
148        source = PAID,
149        destination = REGISTERED),
150
151    Transition(
152        transition_id = 'reset7',
153        title = _('Unregister courses'),
154        msg = _("Courses unregistered"),
155        source = REGISTERED,
156        destination = PAID),
157
158    Transition(
159        transition_id = 'validate_courses',
160        title = _('Validate courses'),
161        msg = _('Courses validated'),
162        source = REGISTERED,
163        destination = VALIDATED),
164
165    Transition(
166        transition_id = 'bypass_validation',
167        title = _('Return and bypass validation'),
168        msg = _("Course validation bypassed"),
169        source = REGISTERED,
170        destination = RETURNING),
171
172    Transition(
173        transition_id = 'reset8',
174        title = _('Reset to school fee paid'),
175        msg = _("Reset to 'school fee paid'"),
176        source = VALIDATED,
177        destination = PAID),
178
179    Transition(
180        transition_id = 'return',
181        title = _('Return'),
182        msg = _("Returned"),
183        source = VALIDATED,
184        destination = RETURNING),
185
186    Transition(
187        transition_id = 'reset9',
188        title = _('Reset to courses validated'),
189        msg = _("Reset to 'courses validated'"),
190        source = RETURNING,
191        destination = VALIDATED),
192
193    # There is no transition to graduated.
194
195    Transition(
196        transition_id = 'request_transcript',
197        title = _('Request transript'),
198        msg = _("Transcript requested"),
199        source = GRADUATED,
200        destination = TRANSCRIPT),
201
202    Transition(
203        transition_id = 'process_transcript',
204        title = _('Transcript processed'),
205        msg = _("Transcript processed"),
206        source = TRANSCRIPT,
207        destination = GRADUATED),
208    )
209
210
211IMPORTABLE_TRANSITIONS = [i.transition_id for i in REGISTRATION_TRANSITIONS]
212
213FORBIDDEN_POSTGRAD_TRANS = ['reset6', 'register_courses']
214
215registration_workflow = KofaWorkflow(REGISTRATION_TRANSITIONS)
216
217class RegistrationWorkflowState(WorkflowState, grok.Adapter):
218    """An adapter to adapt Student objects to workflow states.
219    """
220    grok.context(IStudent)
221    grok.provides(IWorkflowState)
222
223    state_key = 'wf.registration.state'
224    state_id = 'wf.registration.id'
225
226class RegistrationWorkflowInfo(KofaWorkflowInfo, grok.Adapter):
227    """Adapter to adapt Student objects to workflow info objects.
228    """
229    grok.context(IStudent)
230    grok.provides(IKofaWorkflowInfo)
231
232    def __init__(self, context):
233        self.context = context
234        self.wf = registration_workflow
235
236@grok.subscribe(IStudent, IWorkflowTransitionEvent)
237def handle_student_transition_event(obj, event):
238    """Append message to student history and log file when transition happened.
239
240    Lock and unlock clearance form.
241    Trigger actions after school fee payment.
242    """
243
244    msg = event.transition.user_data['msg']
245    history = IObjectHistory(obj)
246    history.addMessage(msg)
247    # School fee payment of returning students triggers the change of
248    # current session, current level, and current verdict
249    if event.transition.transition_id in (
250        'pay_school_fee', 'approve_school_fee'):
251        getUtility(IStudentsUtils).setReturningData(obj)
252    elif event.transition.transition_id in (
253        'pay_pg_fee', 'approve_pg_fee'):
254        new_session = obj['studycourse'].current_session + 1
255        obj['studycourse'].current_session = new_session
256    elif event.transition.transition_id == 'validate_courses':
257        current_level = obj['studycourse'].current_level
258        level_object = obj['studycourse'].get(str(current_level), None)
259        if level_object is not None:
260            user = get_current_principal()
261            if user is None:
262                usertitle = 'system'
263            else:
264                usertitle = getattr(user, 'public_name', None)
265                if not usertitle:
266                    usertitle = user.title
267            level_object.validated_by = usertitle
268            level_object.validation_date = datetime.utcnow()
269    elif event.transition.transition_id == 'clear':
270        obj.officer_comment = None
271    elif event.transition.transition_id == 'reset8':
272        current_level = obj['studycourse'].current_level
273        level_object = obj['studycourse'].get(str(current_level), None)
274        if level_object is not None:
275            level_object.validated_by = None
276            level_object.validation_date = None
277    # In some tests we don't have a students container
278    try:
279        students_container = grok.getSite()['students']
280        students_container.logger.info('%s - %s' % (obj.student_id,msg))
281    except (TypeError, AttributeError):
282        pass
283    return
Note: See TracBrowser for help on using the repository browser.