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

Last change on this file since 9069 was 9028, checked in by Henrik Bettermann, 12 years ago

Disable states and transitions which are not allowed for pg students. Not yet fully tested.

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