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

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

Adjust copyright statement and svn keyword in applicants.

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