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

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

Translate student workflow history messages.

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