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

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

Replace the term 'WAeUP' by SIRP which is a WAeUP product.

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