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

Last change on this file since 14416 was 14281, checked in by Henrik Bettermann, 8 years ago

Take state 'processed' into consideration.

  • Property svn:keywords set to Id
File size: 6.1 KB
Line 
1## $Id: workflow.py 14281 2016-11-17 13:53:42Z 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    )
160
161application_workflow = KofaWorkflow(APPLICATION_TRANSITIONS)
162
163class ApplicationWorkflowState(WorkflowState, grok.Adapter):
164    """An adapter to adapt Applicant objects to workflow states.
165    """
166    grok.context(IApplicantBaseData)
167    grok.provides(IWorkflowState)
168
169    state_key = 'wf.application.state'
170    state_id = 'wf.application.id'
171
172class ApplicationWorkflowInfo(KofaWorkflowInfo, grok.Adapter):
173    """Adapter to adapt Applicant objects to workflow info objects.
174    """
175    grok.context(IApplicantBaseData)
176    grok.provides(IKofaWorkflowInfo)
177
178    def __init__(self, context):
179        self.context = context
180        self.wf = application_workflow
181
182@grok.subscribe(IApplicantBaseData, IWorkflowTransitionEvent)
183def handle_applicant_transition_event(obj, event):
184    """Append message to applicant history and lock form
185    when transition happened.
186    """
187    msg = event.transition.user_data['msg']
188    if event.transition.transition_id == 'create':
189        msg += ' (%s)' % obj.student_id
190        obj.locked = True
191    if event.transition.transition_id == 'submit':
192        obj.locked = True
193    history = IObjectHistory(obj)
194    history.addMessage(msg)
195    # In some tests we don't have a an applicants root or a user
196    try:
197        applicants_root = grok.getSite()['applicants']
198        applicants_root.logger.info('%s - %s' % (obj.applicant_id,msg))
199    except (TypeError, AttributeError):
200        pass
201    return
Note: See TracBrowser for help on using the repository browser.