[10800] | 1 | ## $Id: workflow.py 10801 2013-11-28 13:44:18Z 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 | ## |
---|
| 18 | """Customized workflow for applicants. |
---|
| 19 | """ |
---|
| 20 | import grok |
---|
| 21 | from hurry.workflow.workflow import Transition, WorkflowState, NullCondition |
---|
| 22 | from hurry.workflow.interfaces import IWorkflowState, IWorkflowTransitionEvent |
---|
| 23 | from waeup.kofa.applicants.interfaces import IApplicantBaseData |
---|
| 24 | from waeup.kofa.interfaces import IObjectHistory, IKofaWorkflowInfo, IKofaUtils |
---|
| 25 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
| 26 | from waeup.kofa.workflow import KofaWorkflow, KofaWorkflowInfo |
---|
| 27 | from waeup.kofa.applicants.workflow import ( ApplicationWorkflowInfo, |
---|
| 28 | INITIALIZED, STARTED, SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED) |
---|
| 29 | |
---|
| 30 | APPLICATION_TRANSITIONS = ( |
---|
| 31 | Transition( |
---|
| 32 | transition_id = 'init', |
---|
[10801] | 33 | title = _('Initialize subscription'), |
---|
[10800] | 34 | source = None, |
---|
| 35 | condition = NullCondition, |
---|
[10801] | 36 | msg = _('Subscription initialized'), |
---|
[10800] | 37 | destination = INITIALIZED), |
---|
| 38 | |
---|
| 39 | Transition( |
---|
| 40 | transition_id = 'start', |
---|
[10801] | 41 | title = _('Start subscription'), |
---|
| 42 | msg = _('Subscription started'), |
---|
[10800] | 43 | source = INITIALIZED, |
---|
| 44 | destination = STARTED), |
---|
| 45 | |
---|
| 46 | Transition( |
---|
| 47 | transition_id = 'submit', |
---|
[10801] | 48 | title = _('Submit subscription'), |
---|
| 49 | msg = _('Subscription submitted'), |
---|
[10800] | 50 | source = STARTED, |
---|
| 51 | destination = SUBMITTED), |
---|
| 52 | |
---|
| 53 | Transition( |
---|
| 54 | transition_id = 'admit', |
---|
[10801] | 55 | title = _('Approve subscription'), |
---|
| 56 | msg = _('Subscription approved'), |
---|
[10800] | 57 | source = SUBMITTED, |
---|
| 58 | destination = ADMITTED), |
---|
| 59 | |
---|
| 60 | Transition( |
---|
| 61 | transition_id = 'refuse1', |
---|
[10801] | 62 | title = _('Refuse subscription'), |
---|
| 63 | msg = _('Subscription refused'), |
---|
[10800] | 64 | source = SUBMITTED, |
---|
| 65 | destination = NOT_ADMITTED), |
---|
| 66 | |
---|
| 67 | Transition( |
---|
| 68 | transition_id = 'refuse2', |
---|
[10801] | 69 | title = _('Refuse subscription'), |
---|
| 70 | msg = _('Subscription refused'), |
---|
[10800] | 71 | source = ADMITTED, |
---|
| 72 | destination = NOT_ADMITTED), |
---|
| 73 | |
---|
| 74 | Transition( |
---|
| 75 | transition_id = 'create', |
---|
| 76 | title = _('Create student record'), |
---|
[10801] | 77 | msg = _('Customer record created'), |
---|
[10800] | 78 | source = ADMITTED, |
---|
| 79 | destination = CREATED), |
---|
| 80 | |
---|
| 81 | Transition( |
---|
| 82 | transition_id = 'reset1', |
---|
[10801] | 83 | title = _('Reset subscription to started'), |
---|
| 84 | msg = _('Subscription reset'), |
---|
[10800] | 85 | source = SUBMITTED, |
---|
| 86 | destination = STARTED), |
---|
| 87 | |
---|
| 88 | Transition( |
---|
| 89 | transition_id = 'reset2', |
---|
[10801] | 90 | title = _('Reset subscription to started'), |
---|
| 91 | msg = _('Subscription reset'), |
---|
[10800] | 92 | source = ADMITTED, |
---|
| 93 | destination = STARTED), |
---|
| 94 | |
---|
| 95 | Transition( |
---|
| 96 | transition_id = 'reset3', |
---|
[10801] | 97 | title = _('Reset subscription to started'), |
---|
| 98 | msg = _('Subscription reset'), |
---|
[10800] | 99 | source = NOT_ADMITTED, |
---|
| 100 | destination = STARTED), |
---|
| 101 | |
---|
| 102 | Transition( |
---|
| 103 | transition_id = 'reset4', |
---|
[10801] | 104 | title = _('Reset subscription to started'), |
---|
| 105 | msg = _('Subscription reset'), |
---|
[10800] | 106 | source = CREATED, |
---|
| 107 | destination = STARTED), |
---|
| 108 | |
---|
| 109 | Transition( |
---|
| 110 | transition_id = 'reset7', |
---|
[10801] | 111 | title = _('Reset subscription to admitted'), |
---|
| 112 | msg = _('Subscription reset to admitted'), |
---|
[10800] | 113 | source = CREATED, |
---|
| 114 | destination = ADMITTED), |
---|
| 115 | ) |
---|
| 116 | |
---|
| 117 | application_workflow = KofaWorkflow(APPLICATION_TRANSITIONS) |
---|
| 118 | |
---|
| 119 | class CustomApplicationWorkflowInfo(ApplicationWorkflowInfo): |
---|
| 120 | """Adapter to adapt Applicant objects to workflow info objects. |
---|
| 121 | """ |
---|
| 122 | |
---|
| 123 | def __init__(self, context): |
---|
| 124 | self.context = context |
---|
| 125 | self.wf = application_workflow |
---|