source: main/waeup.sirp/trunk/src/waeup/sirp/applicants/workflow.py @ 7686

Last change on this file since 7686 was 7686, checked in by Henrik Bettermann, 13 years ago

Enable translation of application_state.

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