[7192] | 1 | ## $Id: workflow.py 13108 2015-06-26 14:42:37Z henrik $ |
---|
| 2 | ## |
---|
| 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
| 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
| 8 | ## |
---|
| 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
| 13 | ## |
---|
| 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
[6295] | 18 | """Workflow for applicants. |
---|
| 19 | """ |
---|
| 20 | import grok |
---|
[6353] | 21 | from hurry.workflow.workflow import Transition, WorkflowState, NullCondition |
---|
| 22 | from hurry.workflow.interfaces import IWorkflowState, IWorkflowTransitionEvent |
---|
[7811] | 23 | from waeup.kofa.applicants.interfaces import IApplicantBaseData |
---|
[7819] | 24 | from waeup.kofa.interfaces import IObjectHistory, IKofaWorkflowInfo, IKofaUtils |
---|
[7811] | 25 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
[7819] | 26 | from waeup.kofa.workflow import KofaWorkflow, KofaWorkflowInfo |
---|
[6295] | 27 | |
---|
| 28 | INITIALIZED = 'initialized' |
---|
| 29 | STARTED = 'started' |
---|
[7250] | 30 | PAID = 'paid' |
---|
[6295] | 31 | SUBMITTED = 'submitted' |
---|
| 32 | ADMITTED = 'admitted' |
---|
| 33 | NOT_ADMITTED = 'not admitted' |
---|
| 34 | CREATED = 'created' |
---|
| 35 | |
---|
[8373] | 36 | IMPORTABLE_STATES = (INITIALIZED, STARTED, PAID, SUBMITTED, ADMITTED, NOT_ADMITTED) |
---|
[8290] | 37 | |
---|
[7686] | 38 | application_states_dict = { |
---|
| 39 | INITIALIZED: _('initialized'), |
---|
| 40 | STARTED: _('started'), |
---|
| 41 | PAID: _('paid'), |
---|
| 42 | SUBMITTED: _('submitted'), |
---|
| 43 | ADMITTED: _('admitted'), |
---|
| 44 | NOT_ADMITTED: _('not admitted'), |
---|
| 45 | CREATED: _('created'), |
---|
| 46 | } |
---|
| 47 | |
---|
[6354] | 48 | APPLICATION_TRANSITIONS = ( |
---|
[6353] | 49 | Transition( |
---|
[6295] | 50 | transition_id = 'init', |
---|
[7687] | 51 | title = _('Initialize application'), |
---|
[6295] | 52 | source = None, |
---|
| 53 | condition = NullCondition, |
---|
[7687] | 54 | msg = _('Application initialized'), |
---|
[6353] | 55 | destination = INITIALIZED), |
---|
[6295] | 56 | |
---|
[6353] | 57 | Transition( |
---|
[6295] | 58 | transition_id = 'start', |
---|
[7687] | 59 | title = _('Start application'), |
---|
| 60 | msg = _('Application started'), |
---|
[6295] | 61 | source = INITIALIZED, |
---|
[6353] | 62 | destination = STARTED), |
---|
[6295] | 63 | |
---|
[6353] | 64 | Transition( |
---|
[7250] | 65 | transition_id = 'pay', |
---|
[8260] | 66 | title = _('Pay application fee'), |
---|
[8434] | 67 | msg = _('Payment made'), |
---|
[7250] | 68 | source = STARTED, |
---|
| 69 | destination = PAID), |
---|
| 70 | |
---|
| 71 | Transition( |
---|
[8434] | 72 | transition_id = 'approve', |
---|
| 73 | title = _('Approve payment'), |
---|
| 74 | msg = _('Payment approved'), |
---|
| 75 | source = STARTED, |
---|
| 76 | destination = PAID), |
---|
| 77 | |
---|
| 78 | Transition( |
---|
[6295] | 79 | transition_id = 'submit', |
---|
[7687] | 80 | title = _('Submit application'), |
---|
| 81 | msg = _('Application submitted'), |
---|
[7250] | 82 | source = PAID, |
---|
[6353] | 83 | destination = SUBMITTED), |
---|
[6295] | 84 | |
---|
[6353] | 85 | Transition( |
---|
[6295] | 86 | transition_id = 'admit', |
---|
[7687] | 87 | title = _('Admit applicant'), |
---|
| 88 | msg = _('Applicant admitted'), |
---|
[6295] | 89 | source = SUBMITTED, |
---|
[6353] | 90 | destination = ADMITTED), |
---|
[6295] | 91 | |
---|
[6353] | 92 | Transition( |
---|
[6300] | 93 | transition_id = 'refuse1', |
---|
[7687] | 94 | title = _('Refuse application'), |
---|
| 95 | msg = _('Application refused'), |
---|
[6295] | 96 | source = SUBMITTED, |
---|
[6353] | 97 | destination = NOT_ADMITTED), |
---|
[6295] | 98 | |
---|
[6353] | 99 | Transition( |
---|
[6300] | 100 | transition_id = 'refuse2', |
---|
[7687] | 101 | title = _('Refuse application'), |
---|
| 102 | msg = _('Application refused'), |
---|
[6300] | 103 | source = ADMITTED, |
---|
[6353] | 104 | destination = NOT_ADMITTED), |
---|
[6300] | 105 | |
---|
[6353] | 106 | Transition( |
---|
[6295] | 107 | transition_id = 'create', |
---|
[13108] | 108 | title = _('Create student'), |
---|
[7687] | 109 | msg = _('Student record created'), |
---|
[6295] | 110 | source = ADMITTED, |
---|
[6353] | 111 | destination = CREATED), |
---|
[6295] | 112 | |
---|
[6353] | 113 | Transition( |
---|
[6300] | 114 | transition_id = 'reset1', |
---|
[7687] | 115 | title = _('Reset application to started'), |
---|
| 116 | msg = _('Application reset'), |
---|
[13087] | 117 | source = PAID, |
---|
[6353] | 118 | destination = STARTED), |
---|
[6295] | 119 | |
---|
[6353] | 120 | Transition( |
---|
[6300] | 121 | transition_id = 'reset2', |
---|
[13087] | 122 | title = _('Reset application to paid'), |
---|
| 123 | msg = _('Application reset to paid'), |
---|
| 124 | source = SUBMITTED, |
---|
| 125 | destination = PAID), |
---|
[6300] | 126 | |
---|
[6353] | 127 | Transition( |
---|
[6300] | 128 | transition_id = 'reset3', |
---|
[7687] | 129 | title = _('Reset application to started'), |
---|
| 130 | msg = _('Application reset'), |
---|
[13087] | 131 | source = SUBMITTED, |
---|
[6353] | 132 | destination = STARTED), |
---|
[6300] | 133 | |
---|
[6353] | 134 | Transition( |
---|
[6300] | 135 | transition_id = 'reset4', |
---|
[7687] | 136 | title = _('Reset application to started'), |
---|
| 137 | msg = _('Application reset'), |
---|
[13087] | 138 | source = ADMITTED, |
---|
[6353] | 139 | destination = STARTED), |
---|
[10358] | 140 | |
---|
[7250] | 141 | Transition( |
---|
| 142 | transition_id = 'reset5', |
---|
[8752] | 143 | title = _('Reset application to started'), |
---|
| 144 | msg = _('Application reset'), |
---|
[13087] | 145 | source = NOT_ADMITTED, |
---|
[8752] | 146 | destination = STARTED), |
---|
[10358] | 147 | |
---|
[6353] | 148 | ) |
---|
[6300] | 149 | |
---|
[7819] | 150 | application_workflow = KofaWorkflow(APPLICATION_TRANSITIONS) |
---|
[6295] | 151 | |
---|
[6349] | 152 | class ApplicationWorkflowState(WorkflowState, grok.Adapter): |
---|
[6295] | 153 | """An adapter to adapt Applicant objects to workflow states. |
---|
| 154 | """ |
---|
| 155 | grok.context(IApplicantBaseData) |
---|
| 156 | grok.provides(IWorkflowState) |
---|
[6316] | 157 | |
---|
[6349] | 158 | state_key = 'wf.application.state' |
---|
| 159 | state_id = 'wf.application.id' |
---|
| 160 | |
---|
[7819] | 161 | class ApplicationWorkflowInfo(KofaWorkflowInfo, grok.Adapter): |
---|
[6295] | 162 | """Adapter to adapt Applicant objects to workflow info objects. |
---|
| 163 | """ |
---|
| 164 | grok.context(IApplicantBaseData) |
---|
[7819] | 165 | grok.provides(IKofaWorkflowInfo) |
---|
[6318] | 166 | |
---|
[6349] | 167 | def __init__(self, context): |
---|
| 168 | self.context = context |
---|
| 169 | self.wf = application_workflow |
---|
[6318] | 170 | |
---|
| 171 | @grok.subscribe(IApplicantBaseData, IWorkflowTransitionEvent) |
---|
| 172 | def handle_applicant_transition_event(obj, event): |
---|
[11794] | 173 | """Append message to applicant history and lock form |
---|
| 174 | when transition happened. |
---|
[6318] | 175 | """ |
---|
[7687] | 176 | msg = event.transition.user_data['msg'] |
---|
[8312] | 177 | if event.transition.transition_id == 'create': |
---|
| 178 | msg += ' (%s)' % obj.student_id |
---|
[9398] | 179 | obj.locked = True |
---|
| 180 | if event.transition.transition_id == 'submit': |
---|
| 181 | obj.locked = True |
---|
[6339] | 182 | history = IObjectHistory(obj) |
---|
| 183 | history.addMessage(msg) |
---|
[6644] | 184 | # In some tests we don't have a an applicants root or a user |
---|
[8335] | 185 | try: |
---|
| 186 | applicants_root = grok.getSite()['applicants'] |
---|
| 187 | applicants_root.logger.info('%s - %s' % (obj.applicant_id,msg)) |
---|
| 188 | except (TypeError, AttributeError): |
---|
| 189 | pass |
---|
[6318] | 190 | return |
---|