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