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

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

Managers do not 'pay' fees for applicants and students, they approve payments made.

Add respective transitions.

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