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

Last change on this file since 15057 was 14281, checked in by Henrik Bettermann, 8 years ago

Take state 'processed' into consideration.

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