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