[7192] | 1 | ## $Id: workflow.py 7652 2012-02-15 10:51:53Z 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 |
---|
[6295] | 23 | from waeup.sirp.applicants.interfaces import IApplicantBaseData |
---|
[7321] | 24 | from waeup.sirp.interfaces import IObjectHistory, ISIRPWorkflowInfo |
---|
| 25 | from waeup.sirp.workflow import SIRPWorkflow, SIRPWorkflowInfo |
---|
[6295] | 26 | |
---|
| 27 | INITIALIZED = 'initialized' |
---|
| 28 | STARTED = 'started' |
---|
[7250] | 29 | PAID = 'paid' |
---|
[6295] | 30 | SUBMITTED = 'submitted' |
---|
| 31 | ADMITTED = 'admitted' |
---|
| 32 | NOT_ADMITTED = 'not admitted' |
---|
| 33 | CREATED = 'created' |
---|
| 34 | |
---|
[6354] | 35 | APPLICATION_TRANSITIONS = ( |
---|
[6353] | 36 | Transition( |
---|
[6295] | 37 | transition_id = 'init', |
---|
[6306] | 38 | title = 'Initialize application', |
---|
[6295] | 39 | source = None, |
---|
| 40 | condition = NullCondition, |
---|
[6471] | 41 | msg = 'Application initialized', |
---|
[6353] | 42 | destination = INITIALIZED), |
---|
[6295] | 43 | |
---|
[6353] | 44 | Transition( |
---|
[6295] | 45 | transition_id = 'start', |
---|
[6300] | 46 | title = 'Start application', |
---|
[6471] | 47 | msg = 'Application started', |
---|
[6295] | 48 | source = INITIALIZED, |
---|
[6353] | 49 | destination = STARTED), |
---|
[6295] | 50 | |
---|
[6353] | 51 | Transition( |
---|
[7250] | 52 | transition_id = 'pay', |
---|
| 53 | title = 'Pay acceptance fee', |
---|
| 54 | msg = 'Fee paid', |
---|
| 55 | source = STARTED, |
---|
| 56 | destination = PAID), |
---|
| 57 | |
---|
| 58 | Transition( |
---|
[6295] | 59 | transition_id = 'submit', |
---|
[6307] | 60 | title = 'Submit application', |
---|
[6471] | 61 | msg = 'Application submitted', |
---|
[7250] | 62 | source = PAID, |
---|
[6353] | 63 | destination = SUBMITTED), |
---|
[6295] | 64 | |
---|
[6353] | 65 | Transition( |
---|
[6295] | 66 | transition_id = 'admit', |
---|
[6300] | 67 | title = 'Admit applicant', |
---|
[6471] | 68 | msg = 'Applicant admitted', |
---|
[6295] | 69 | source = SUBMITTED, |
---|
[6353] | 70 | destination = ADMITTED), |
---|
[6295] | 71 | |
---|
[6353] | 72 | Transition( |
---|
[6300] | 73 | transition_id = 'refuse1', |
---|
| 74 | title = 'Refuse application', |
---|
[6471] | 75 | msg = 'Application refused', |
---|
[6295] | 76 | source = SUBMITTED, |
---|
[6353] | 77 | destination = NOT_ADMITTED), |
---|
[6295] | 78 | |
---|
[6353] | 79 | Transition( |
---|
[6300] | 80 | transition_id = 'refuse2', |
---|
| 81 | title = 'Refuse application', |
---|
[6471] | 82 | msg = 'Application refused', |
---|
[6300] | 83 | source = ADMITTED, |
---|
[6353] | 84 | destination = NOT_ADMITTED), |
---|
[6300] | 85 | |
---|
[6353] | 86 | Transition( |
---|
[6295] | 87 | transition_id = 'create', |
---|
[6307] | 88 | title = 'Create student record', |
---|
[6471] | 89 | msg = 'Student record created', |
---|
[6295] | 90 | source = ADMITTED, |
---|
[6353] | 91 | destination = CREATED), |
---|
[6295] | 92 | |
---|
[6353] | 93 | Transition( |
---|
[6300] | 94 | transition_id = 'reset1', |
---|
[7250] | 95 | title = 'Reset application to started', |
---|
[6471] | 96 | msg = 'Application reset', |
---|
[6300] | 97 | source = SUBMITTED, |
---|
[6353] | 98 | destination = STARTED), |
---|
[6295] | 99 | |
---|
[6353] | 100 | Transition( |
---|
[6300] | 101 | transition_id = 'reset2', |
---|
[7250] | 102 | title = 'Reset application to started', |
---|
[6471] | 103 | msg = 'Application reset', |
---|
[6300] | 104 | source = ADMITTED, |
---|
[6353] | 105 | destination = STARTED), |
---|
[6300] | 106 | |
---|
[6353] | 107 | Transition( |
---|
[6300] | 108 | transition_id = 'reset3', |
---|
[7250] | 109 | title = 'Reset application to started', |
---|
[6471] | 110 | msg = 'Application reset', |
---|
[6300] | 111 | source = NOT_ADMITTED, |
---|
[6353] | 112 | destination = STARTED), |
---|
[6300] | 113 | |
---|
[6353] | 114 | Transition( |
---|
[6300] | 115 | transition_id = 'reset4', |
---|
[7250] | 116 | title = 'Reset application to started', |
---|
[6471] | 117 | msg = 'Application reset', |
---|
[6300] | 118 | source = CREATED, |
---|
[6353] | 119 | destination = STARTED), |
---|
[7250] | 120 | Transition( |
---|
| 121 | transition_id = 'reset5', |
---|
| 122 | title = 'Reset application to paid', |
---|
| 123 | msg = 'Application reset', |
---|
| 124 | source = SUBMITTED, |
---|
| 125 | destination = PAID), |
---|
[6353] | 126 | ) |
---|
[6300] | 127 | |
---|
[7321] | 128 | application_workflow = SIRPWorkflow(APPLICATION_TRANSITIONS) |
---|
[6295] | 129 | |
---|
[6349] | 130 | class ApplicationWorkflowState(WorkflowState, grok.Adapter): |
---|
[6295] | 131 | """An adapter to adapt Applicant objects to workflow states. |
---|
| 132 | """ |
---|
| 133 | grok.context(IApplicantBaseData) |
---|
| 134 | grok.provides(IWorkflowState) |
---|
[6316] | 135 | |
---|
[6349] | 136 | state_key = 'wf.application.state' |
---|
| 137 | state_id = 'wf.application.id' |
---|
| 138 | |
---|
[7321] | 139 | class ApplicationWorkflowInfo(SIRPWorkflowInfo, grok.Adapter): |
---|
[6295] | 140 | """Adapter to adapt Applicant objects to workflow info objects. |
---|
| 141 | """ |
---|
| 142 | grok.context(IApplicantBaseData) |
---|
[7321] | 143 | grok.provides(ISIRPWorkflowInfo) |
---|
[6318] | 144 | |
---|
[6349] | 145 | def __init__(self, context): |
---|
| 146 | self.context = context |
---|
| 147 | self.wf = application_workflow |
---|
[6318] | 148 | |
---|
| 149 | @grok.subscribe(IApplicantBaseData, IWorkflowTransitionEvent) |
---|
| 150 | def handle_applicant_transition_event(obj, event): |
---|
[6471] | 151 | """Append message to applicant history when transition happened. |
---|
[6318] | 152 | """ |
---|
[6471] | 153 | msg = '%s' % event.transition.user_data['msg'] |
---|
[6339] | 154 | history = IObjectHistory(obj) |
---|
| 155 | history.addMessage(msg) |
---|
[6644] | 156 | # In some tests we don't have a an applicants root or a user |
---|
| 157 | try: |
---|
| 158 | applicants_root = grok.getSite()['applicants'] |
---|
[7652] | 159 | applicants_root.logger.info('%s - %s' % (obj.applicant_id,msg)) |
---|
[6644] | 160 | except (TypeError, AttributeError): |
---|
| 161 | pass |
---|
[6318] | 162 | return |
---|