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

Last change on this file since 13810 was 13651, checked in by Henrik Bettermann, 9 years ago

Add new application workflow state (processed) and transition (process).

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