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