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

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

Log applicant_id not access_code.

Histories should contain real names not user ids.

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