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

Last change on this file since 14024 was 13651, checked in by Henrik Bettermann, 9 years ago

Add new application workflow state (processed) and transition (process).

  • Property svn:keywords set to Id
File size: 6.1 KB
RevLine 
[7192]1## $Id: workflow.py 13651 2016-02-05 08:48:02Z 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'
[13651]35PROCESSED = 'processed'
[6295]36
[13651]37
[8373]38IMPORTABLE_STATES = (INITIALIZED, STARTED, PAID, SUBMITTED, ADMITTED, NOT_ADMITTED)
[8290]39
[7686]40application_states_dict = {
41    INITIALIZED: _('initialized'),
42    STARTED: _('started'),
43    PAID: _('paid'),
44    SUBMITTED: _('submitted'),
45    ADMITTED: _('admitted'),
46    NOT_ADMITTED: _('not admitted'),
47    CREATED: _('created'),
[13651]48    PROCESSED: _('processed'),
[7686]49    }
50
[6354]51APPLICATION_TRANSITIONS = (
[6353]52    Transition(
[6295]53        transition_id = 'init',
[7687]54        title = _('Initialize application'),
[6295]55        source = None,
56        condition = NullCondition,
[7687]57        msg = _('Application initialized'),
[6353]58        destination = INITIALIZED),
[6295]59
[6353]60    Transition(
[6295]61        transition_id = 'start',
[7687]62        title = _('Start application'),
63        msg = _('Application started'),
[6295]64        source = INITIALIZED,
[6353]65        destination = STARTED),
[6295]66
[6353]67    Transition(
[7250]68        transition_id = 'pay',
[8260]69        title = _('Pay application fee'),
[8434]70        msg = _('Payment made'),
[7250]71        source = STARTED,
72        destination = PAID),
73
74    Transition(
[8434]75        transition_id = 'approve',
76        title = _('Approve payment'),
77        msg = _('Payment approved'),
78        source = STARTED,
79        destination = PAID),
80
81    Transition(
[6295]82        transition_id = 'submit',
[7687]83        title = _('Submit application'),
84        msg = _('Application submitted'),
[7250]85        source = PAID,
[6353]86        destination = SUBMITTED),
[6295]87
[6353]88    Transition(
[6295]89        transition_id = 'admit',
[7687]90        title = _('Admit applicant'),
91        msg = _('Applicant admitted'),
[6295]92        source = SUBMITTED,
[6353]93        destination = ADMITTED),
[6295]94
[6353]95    Transition(
[6300]96        transition_id = 'refuse1',
[7687]97        title = _('Refuse application'),
98        msg = _('Application refused'),
[6295]99        source = SUBMITTED,
[6353]100        destination = NOT_ADMITTED),
[6295]101
[6353]102    Transition(
[13651]103        transition_id = 'process',
104        title = _('Process application'),
105        msg = _('Application processed'),
106        source = SUBMITTED,
107        destination = PROCESSED),
108
109    Transition(
[6300]110        transition_id = 'refuse2',
[7687]111        title = _('Refuse application'),
112        msg = _('Application refused'),
[6300]113        source = ADMITTED,
[6353]114        destination = NOT_ADMITTED),
[6300]115
[6353]116    Transition(
[6295]117        transition_id = 'create',
[13108]118        title = _('Create student'),
[7687]119        msg = _('Student record created'),
[6295]120        source = ADMITTED,
[6353]121        destination = CREATED),
[6295]122
[6353]123    Transition(
[6300]124        transition_id = 'reset1',
[7687]125        title = _('Reset application to started'),
126        msg = _('Application reset'),
[13087]127        source = PAID,
[6353]128        destination = STARTED),
[6295]129
[6353]130    Transition(
[6300]131        transition_id = 'reset2',
[13087]132        title = _('Reset application to paid'),
133        msg = _('Application reset to paid'),
134        source = SUBMITTED,
135        destination = PAID),
[6300]136
[6353]137    Transition(
[6300]138        transition_id = 'reset3',
[7687]139        title = _('Reset application to started'),
140        msg = _('Application reset'),
[13087]141        source = SUBMITTED,
[6353]142        destination = STARTED),
[6300]143
[6353]144    Transition(
[6300]145        transition_id = 'reset4',
[7687]146        title = _('Reset application to started'),
147        msg = _('Application reset'),
[13087]148        source = ADMITTED,
[6353]149        destination = STARTED),
[10358]150
[7250]151    Transition(
152        transition_id = 'reset5',
[8752]153        title = _('Reset application to started'),
154        msg = _('Application reset'),
[13087]155        source = NOT_ADMITTED,
[8752]156        destination = STARTED),
[10358]157
[6353]158    )
[6300]159
[7819]160application_workflow = KofaWorkflow(APPLICATION_TRANSITIONS)
[6295]161
[6349]162class ApplicationWorkflowState(WorkflowState, grok.Adapter):
[6295]163    """An adapter to adapt Applicant objects to workflow states.
164    """
165    grok.context(IApplicantBaseData)
166    grok.provides(IWorkflowState)
[6316]167
[6349]168    state_key = 'wf.application.state'
169    state_id = 'wf.application.id'
170
[7819]171class ApplicationWorkflowInfo(KofaWorkflowInfo, grok.Adapter):
[6295]172    """Adapter to adapt Applicant objects to workflow info objects.
173    """
174    grok.context(IApplicantBaseData)
[7819]175    grok.provides(IKofaWorkflowInfo)
[6318]176
[6349]177    def __init__(self, context):
178        self.context = context
179        self.wf = application_workflow
[6318]180
181@grok.subscribe(IApplicantBaseData, IWorkflowTransitionEvent)
182def handle_applicant_transition_event(obj, event):
[11794]183    """Append message to applicant history and lock form
184    when transition happened.
[6318]185    """
[7687]186    msg = event.transition.user_data['msg']
[8312]187    if event.transition.transition_id == 'create':
188        msg += ' (%s)' % obj.student_id
[9398]189        obj.locked = True
190    if event.transition.transition_id == 'submit':
191        obj.locked = True
[6339]192    history = IObjectHistory(obj)
193    history.addMessage(msg)
[6644]194    # In some tests we don't have a an applicants root or a user
[8335]195    try:
196        applicants_root = grok.getSite()['applicants']
197        applicants_root.logger.info('%s - %s' % (obj.applicant_id,msg))
198    except (TypeError, AttributeError):
199        pass
[6318]200    return
Note: See TracBrowser for help on using the repository browser.