[6637] | 1 | """Workflow for students. |
---|
| 2 | """ |
---|
| 3 | import grok |
---|
[7615] | 4 | from zope.component import getUtility |
---|
[7679] | 5 | from zope.i18n import translate |
---|
[6637] | 6 | from hurry.workflow.workflow import Transition, WorkflowState, NullCondition |
---|
| 7 | from hurry.workflow.interfaces import IWorkflowState, IWorkflowTransitionEvent |
---|
[6990] | 8 | from waeup.sirp.interfaces import ( |
---|
[7679] | 9 | IObjectHistory, ISIRPWorkflowInfo, ISIRPUtils, |
---|
[6990] | 10 | CREATED, ADMITTED, CLEARANCE, REQUESTED, CLEARED, PAID, RETURNING, |
---|
| 11 | REGISTERED, VALIDATED) |
---|
[7670] | 12 | from waeup.sirp.interfaces import MessageFactory as _ |
---|
[7321] | 13 | from waeup.sirp.workflow import SIRPWorkflow, SIRPWorkflowInfo |
---|
[7615] | 14 | from waeup.sirp.students.interfaces import IStudent, IStudentsUtils |
---|
[6637] | 15 | |
---|
[7615] | 16 | |
---|
[7513] | 17 | IMPORTABLE_STATES = (ADMITTED, CLEARANCE, REQUESTED, CLEARED, PAID, RETURNING, |
---|
| 18 | REGISTERED, VALIDATED) |
---|
| 19 | |
---|
[6637] | 20 | REGISTRATION_TRANSITIONS = ( |
---|
| 21 | Transition( |
---|
| 22 | transition_id = 'create', |
---|
[7677] | 23 | title = _('Create student'), |
---|
[6637] | 24 | source = None, |
---|
| 25 | condition = NullCondition, |
---|
[7677] | 26 | msg = _('Student record created'), |
---|
[6637] | 27 | destination = CREATED), |
---|
| 28 | |
---|
| 29 | Transition( |
---|
| 30 | transition_id = 'admit', |
---|
[7670] | 31 | title = _('Admit student'), |
---|
[7677] | 32 | msg = _('Student admitted'), |
---|
[6637] | 33 | source = CREATED, |
---|
| 34 | destination = ADMITTED), |
---|
| 35 | |
---|
| 36 | Transition( |
---|
| 37 | transition_id = 'reset1', |
---|
[7677] | 38 | title = _('Reset student'), |
---|
| 39 | msg = _('Student record reset'), |
---|
[6637] | 40 | source = ADMITTED, |
---|
| 41 | destination = CREATED), |
---|
[6720] | 42 | |
---|
| 43 | Transition( |
---|
| 44 | transition_id = 'start_clearance', |
---|
[7677] | 45 | title = _('Start clearance'), |
---|
| 46 | msg = _('Clearance started'), |
---|
[6720] | 47 | source = ADMITTED, |
---|
| 48 | destination = CLEARANCE), |
---|
| 49 | |
---|
| 50 | Transition( |
---|
| 51 | transition_id = 'reset2', |
---|
[7677] | 52 | title = _('Reset to admitted'), |
---|
| 53 | msg = _("Student record reset to 'admitted'"), |
---|
[6720] | 54 | source = CLEARANCE, |
---|
| 55 | destination = ADMITTED), |
---|
| 56 | |
---|
| 57 | Transition( |
---|
| 58 | transition_id = 'request_clearance', |
---|
[7677] | 59 | title = _('Request clearance'), |
---|
| 60 | msg = _('Clearance requested'), |
---|
[6720] | 61 | source = CLEARANCE, |
---|
| 62 | destination = REQUESTED), |
---|
| 63 | |
---|
| 64 | Transition( |
---|
| 65 | transition_id = 'reset3', |
---|
[7677] | 66 | title = _('Reset to clearance'), |
---|
| 67 | msg = _("Student record reset to 'clearance'"), |
---|
[6720] | 68 | source = REQUESTED, |
---|
| 69 | destination = CLEARANCE), |
---|
| 70 | |
---|
| 71 | Transition( |
---|
| 72 | transition_id = 'clear', |
---|
[7677] | 73 | title = _('Clear student'), |
---|
| 74 | msg = _('Cleared'), |
---|
[6720] | 75 | source = REQUESTED, |
---|
| 76 | destination = CLEARED), |
---|
| 77 | |
---|
| 78 | Transition( |
---|
| 79 | transition_id = 'reset4', |
---|
[7677] | 80 | title = _('Reset to clearance'), |
---|
| 81 | msg = _("Student record reset to 'clearance'"), |
---|
[6720] | 82 | source = CLEARED, |
---|
| 83 | destination = CLEARANCE), |
---|
[6742] | 84 | |
---|
| 85 | Transition( |
---|
| 86 | transition_id = 'pay_first_school_fee', |
---|
[7677] | 87 | title = _('Pay school fee'), |
---|
| 88 | msg = _('School fee paid'), |
---|
[6742] | 89 | source = CLEARED, |
---|
| 90 | destination = PAID), |
---|
| 91 | |
---|
| 92 | Transition( |
---|
| 93 | transition_id = 'reset5', |
---|
[7677] | 94 | title = _('Reset to cleared'), |
---|
| 95 | msg = _("Student record reset to 'cleared'"), |
---|
[6742] | 96 | source = PAID, |
---|
| 97 | destination = CLEARED), |
---|
| 98 | |
---|
| 99 | Transition( |
---|
| 100 | transition_id = 'pay_school_fee', |
---|
[7677] | 101 | title = _('Pay school fee'), |
---|
| 102 | msg = _('School fee paid'), |
---|
[6742] | 103 | source = RETURNING, |
---|
| 104 | destination = PAID), |
---|
| 105 | |
---|
| 106 | Transition( |
---|
| 107 | transition_id = 'reset6', |
---|
[7677] | 108 | title = _('Reset to returning'), |
---|
| 109 | msg = _("Student record reset to 'returning'"), |
---|
[6742] | 110 | source = PAID, |
---|
| 111 | destination = RETURNING), |
---|
[6801] | 112 | |
---|
| 113 | Transition( |
---|
| 114 | transition_id = 'register_courses', |
---|
[7677] | 115 | title = _('Register courses'), |
---|
| 116 | msg = _('Courses registered'), |
---|
[6801] | 117 | source = PAID, |
---|
| 118 | destination = REGISTERED), |
---|
| 119 | |
---|
| 120 | Transition( |
---|
| 121 | transition_id = 'reset7', |
---|
[7677] | 122 | title = _('Reset to paid'), |
---|
| 123 | msg = _("Student record reset to 'paid'"), |
---|
[6801] | 124 | source = REGISTERED, |
---|
| 125 | destination = PAID), |
---|
| 126 | |
---|
| 127 | Transition( |
---|
| 128 | transition_id = 'validate_courses', |
---|
[7677] | 129 | title = _('Validate courses'), |
---|
| 130 | msg = _('Courses validated'), |
---|
[6801] | 131 | source = REGISTERED, |
---|
| 132 | destination = VALIDATED), |
---|
| 133 | |
---|
| 134 | Transition( |
---|
| 135 | transition_id = 'reset8', |
---|
[7677] | 136 | title = _('Reset to paid'), |
---|
| 137 | msg = _("Student record reset to 'paid'"), |
---|
[6801] | 138 | source = VALIDATED, |
---|
| 139 | destination = PAID), |
---|
| 140 | |
---|
| 141 | Transition( |
---|
| 142 | transition_id = 'return', |
---|
[7677] | 143 | title = _('Return'), |
---|
| 144 | msg = _('Returned'), |
---|
[6801] | 145 | source = VALIDATED, |
---|
| 146 | destination = RETURNING), |
---|
| 147 | |
---|
| 148 | Transition( |
---|
| 149 | transition_id = 'reset9', |
---|
[7677] | 150 | title = _('Reset to validated'), |
---|
| 151 | msg = _("Student record reset to 'validated'"), |
---|
[6801] | 152 | source = RETURNING, |
---|
| 153 | destination = VALIDATED), |
---|
[6637] | 154 | ) |
---|
| 155 | |
---|
[6722] | 156 | LOCK_CLEARANCE_TRANS = ('reset2', 'request_clearance') |
---|
| 157 | UNLOCK_CLEARANCE_TRANS = ('reset3', 'reset4', 'start_clearance') |
---|
[6720] | 158 | |
---|
[7321] | 159 | registration_workflow = SIRPWorkflow(REGISTRATION_TRANSITIONS) |
---|
[6637] | 160 | |
---|
| 161 | class 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 | |
---|
[7321] | 170 | class RegistrationWorkflowInfo(SIRPWorkflowInfo, grok.Adapter): |
---|
[6637] | 171 | """Adapter to adapt Student objects to workflow info objects. |
---|
| 172 | """ |
---|
| 173 | grok.context(IStudent) |
---|
[7321] | 174 | grok.provides(ISIRPWorkflowInfo) |
---|
[6637] | 175 | |
---|
| 176 | def __init__(self, context): |
---|
| 177 | self.context = context |
---|
| 178 | self.wf = registration_workflow |
---|
| 179 | |
---|
| 180 | @grok.subscribe(IStudent, IWorkflowTransitionEvent) |
---|
| 181 | def handle_student_transition_event(obj, event): |
---|
[6644] | 182 | """Append message to student history and log file when transition happened. |
---|
[7133] | 183 | |
---|
[7681] | 184 | Lock and unlock clearance form. |
---|
[6637] | 185 | """ |
---|
[7679] | 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) |
---|
[6637] | 191 | history = IObjectHistory(obj) |
---|
| 192 | history.addMessage(msg) |
---|
[6722] | 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 |
---|
[6742] | 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': |
---|
[7615] | 203 | getUtility(IStudentsUtils).setReturningData(obj) |
---|
[7652] | 204 | # In some tests we don't have a students container |
---|
[6644] | 205 | try: |
---|
| 206 | students_container = grok.getSite()['students'] |
---|
[7652] | 207 | students_container.logger.info('%s - %s' % (obj.student_id,msg)) |
---|
[6644] | 208 | except (TypeError, AttributeError): |
---|
| 209 | pass |
---|
[6637] | 210 | return |
---|