source: main/waeup.kofa/trunk/src/waeup/kofa/applicants/workflow.py @ 7982

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

KOFA -> Kofa

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