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