source: main/waeup.kofa/branches/uli-upgrade-dependencies/src/waeup/kofa/applicants/workflow.py @ 13599

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

Rename button.

Reorganize applicants section docs.

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