source: main/waeup.kofa/trunk/src/waeup/kofa/applicants/workflow.py @ 17760

Last change on this file since 17760 was 15875, checked in by Henrik Bettermann, 5 years ago

Add application worklfow transition reset6.

  • Property svn:keywords set to Id
File size: 6.3 KB
Line 
1## $Id: workflow.py 15875 2019-12-09 14:55:15Z 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"""Workflow for applicants.
19"""
20import grok
21from hurry.workflow.workflow import Transition, WorkflowState, NullCondition
22from hurry.workflow.interfaces import IWorkflowState, IWorkflowTransitionEvent
23from waeup.kofa.applicants.interfaces import IApplicantBaseData
24from waeup.kofa.interfaces import IObjectHistory, IKofaWorkflowInfo, IKofaUtils
25from waeup.kofa.interfaces import MessageFactory as _
26from waeup.kofa.workflow import KofaWorkflow, KofaWorkflowInfo
27
28INITIALIZED = 'initialized'
29STARTED = 'started'
30PAID = 'paid'
31SUBMITTED = 'submitted'
32ADMITTED = 'admitted'
33NOT_ADMITTED = 'not admitted'
34CREATED = 'created'
35PROCESSED = 'processed'
36
37
38IMPORTABLE_STATES = (INITIALIZED, STARTED, PAID,
39                     SUBMITTED, ADMITTED, NOT_ADMITTED, PROCESSED)
40
41application_states_dict = {
42    INITIALIZED: _('initialized'),
43    STARTED: _('started'),
44    PAID: _('paid'),
45    SUBMITTED: _('submitted'),
46    ADMITTED: _('admitted'),
47    NOT_ADMITTED: _('not admitted'),
48    CREATED: _('created'),
49    PROCESSED: _('processed'),
50    }
51
52APPLICATION_TRANSITIONS = (
53    Transition(
54        transition_id = 'init',
55        title = _('Initialize application'),
56        source = None,
57        condition = NullCondition,
58        msg = _('Application initialized'),
59        destination = INITIALIZED),
60
61    Transition(
62        transition_id = 'start',
63        title = _('Start application'),
64        msg = _('Application started'),
65        source = INITIALIZED,
66        destination = STARTED),
67
68    Transition(
69        transition_id = 'pay',
70        title = _('Pay application fee'),
71        msg = _('Payment made'),
72        source = STARTED,
73        destination = PAID),
74
75    Transition(
76        transition_id = 'approve',
77        title = _('Approve payment'),
78        msg = _('Payment approved'),
79        source = STARTED,
80        destination = PAID),
81
82    Transition(
83        transition_id = 'submit',
84        title = _('Submit application'),
85        msg = _('Application submitted'),
86        source = PAID,
87        destination = SUBMITTED),
88
89    Transition(
90        transition_id = 'admit',
91        title = _('Admit applicant'),
92        msg = _('Applicant admitted'),
93        source = SUBMITTED,
94        destination = ADMITTED),
95
96    Transition(
97        transition_id = 'refuse1',
98        title = _('Refuse application'),
99        msg = _('Application refused'),
100        source = SUBMITTED,
101        destination = NOT_ADMITTED),
102
103    Transition(
104        transition_id = 'process',
105        title = _('Process application'),
106        msg = _('Application processed'),
107        source = SUBMITTED,
108        destination = PROCESSED),
109
110    Transition(
111        transition_id = 'refuse2',
112        title = _('Refuse application'),
113        msg = _('Application refused'),
114        source = ADMITTED,
115        destination = NOT_ADMITTED),
116
117    Transition(
118        transition_id = 'create',
119        title = _('Create student'),
120        msg = _('Student record created'),
121        source = ADMITTED,
122        destination = CREATED),
123
124    Transition(
125        transition_id = 'reset1',
126        title = _('Reset application to started'),
127        msg = _('Application reset'),
128        source = PAID,
129        destination = STARTED),
130
131    Transition(
132        transition_id = 'reset2',
133        title = _('Reset application to paid'),
134        msg = _('Application reset to paid'),
135        source = SUBMITTED,
136        destination = PAID),
137
138    Transition(
139        transition_id = 'reset3',
140        title = _('Reset application to started'),
141        msg = _('Application reset'),
142        source = SUBMITTED,
143        destination = STARTED),
144
145    Transition(
146        transition_id = 'reset4',
147        title = _('Reset application to started'),
148        msg = _('Application reset'),
149        source = ADMITTED,
150        destination = STARTED),
151
152    Transition(
153        transition_id = 'reset5',
154        title = _('Reset application to started'),
155        msg = _('Application reset'),
156        source = NOT_ADMITTED,
157        destination = STARTED),
158
159    Transition(
160        transition_id = 'reset6',
161        title = _('Reset application to submitted'),
162        msg = _('Application reset'),
163        source = PROCESSED,
164        destination = SUBMITTED),
165
166    )
167
168application_workflow = KofaWorkflow(APPLICATION_TRANSITIONS)
169
170class ApplicationWorkflowState(WorkflowState, grok.Adapter):
171    """An adapter to adapt Applicant objects to workflow states.
172    """
173    grok.context(IApplicantBaseData)
174    grok.provides(IWorkflowState)
175
176    state_key = 'wf.application.state'
177    state_id = 'wf.application.id'
178
179class ApplicationWorkflowInfo(KofaWorkflowInfo, grok.Adapter):
180    """Adapter to adapt Applicant objects to workflow info objects.
181    """
182    grok.context(IApplicantBaseData)
183    grok.provides(IKofaWorkflowInfo)
184
185    def __init__(self, context):
186        self.context = context
187        self.wf = application_workflow
188
189@grok.subscribe(IApplicantBaseData, IWorkflowTransitionEvent)
190def handle_applicant_transition_event(obj, event):
191    """Append message to applicant history and lock form
192    when transition happened.
193    """
194    msg = event.transition.user_data['msg']
195    if event.transition.transition_id == 'create':
196        msg += ' (%s)' % obj.student_id
197        obj.locked = True
198    if event.transition.transition_id == 'submit':
199        obj.locked = True
200    history = IObjectHistory(obj)
201    history.addMessage(msg)
202    # In some tests we don't have a an applicants root or a user
203    try:
204        applicants_root = grok.getSite()['applicants']
205        applicants_root.logger.info('%s - %s' % (obj.applicant_id,msg))
206    except (TypeError, AttributeError):
207        pass
208    return
Note: See TracBrowser for help on using the repository browser.