1 | ## $Id: workflow.py 10359 2013-06-23 06:06:24Z 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', |
---|
33 | title = _('Initialize application'), |
---|
34 | source = None, |
---|
35 | condition = NullCondition, |
---|
36 | msg = _('Application initialized'), |
---|
37 | destination = INITIALIZED), |
---|
38 | |
---|
39 | Transition( |
---|
40 | transition_id = 'start', |
---|
41 | title = _('Start application'), |
---|
42 | msg = _('Application started'), |
---|
43 | source = INITIALIZED, |
---|
44 | destination = STARTED), |
---|
45 | |
---|
46 | Transition( |
---|
47 | transition_id = 'submit', |
---|
48 | title = _('Submit application'), |
---|
49 | msg = _('Application submitted'), |
---|
50 | source = STARTED, |
---|
51 | destination = SUBMITTED), |
---|
52 | |
---|
53 | Transition( |
---|
54 | transition_id = 'admit', |
---|
55 | title = _('Admit applicant'), |
---|
56 | msg = _('Applicant admitted'), |
---|
57 | source = SUBMITTED, |
---|
58 | destination = ADMITTED), |
---|
59 | |
---|
60 | Transition( |
---|
61 | transition_id = 'refuse1', |
---|
62 | title = _('Refuse application'), |
---|
63 | msg = _('Application refused'), |
---|
64 | source = SUBMITTED, |
---|
65 | destination = NOT_ADMITTED), |
---|
66 | |
---|
67 | Transition( |
---|
68 | transition_id = 'refuse2', |
---|
69 | title = _('Refuse application'), |
---|
70 | msg = _('Application refused'), |
---|
71 | source = ADMITTED, |
---|
72 | destination = NOT_ADMITTED), |
---|
73 | |
---|
74 | Transition( |
---|
75 | transition_id = 'create', |
---|
76 | title = _('Create student record'), |
---|
77 | msg = _('Student record created'), |
---|
78 | source = ADMITTED, |
---|
79 | destination = CREATED), |
---|
80 | |
---|
81 | Transition( |
---|
82 | transition_id = 'reset1', |
---|
83 | title = _('Reset application to started'), |
---|
84 | msg = _('Application reset'), |
---|
85 | source = SUBMITTED, |
---|
86 | destination = STARTED), |
---|
87 | |
---|
88 | Transition( |
---|
89 | transition_id = 'reset2', |
---|
90 | title = _('Reset application to started'), |
---|
91 | msg = _('Application reset'), |
---|
92 | source = ADMITTED, |
---|
93 | destination = STARTED), |
---|
94 | |
---|
95 | Transition( |
---|
96 | transition_id = 'reset3', |
---|
97 | title = _('Reset application to started'), |
---|
98 | msg = _('Application reset'), |
---|
99 | source = NOT_ADMITTED, |
---|
100 | destination = STARTED), |
---|
101 | |
---|
102 | Transition( |
---|
103 | transition_id = 'reset4', |
---|
104 | title = _('Reset application to started'), |
---|
105 | msg = _('Application reset'), |
---|
106 | source = CREATED, |
---|
107 | destination = STARTED), |
---|
108 | |
---|
109 | Transition( |
---|
110 | transition_id = 'reset7', |
---|
111 | title = _('Reset application to admitted'), |
---|
112 | msg = _('Application reset to admitted'), |
---|
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 |
---|