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