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

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

Do not retrieve current principal in derived logging components. This is now done by the parent Logger class.

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