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

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

Do not translate message in event handler bit in addMessage.

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