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

Last change on this file since 17463 was 15875, checked in by Henrik Bettermann, 5 years ago

Add application worklfow transition reset6.

  • Property svn:keywords set to Id
File size: 6.3 KB
RevLine 
[7192]1## $Id: workflow.py 15875 2019-12-09 14:55:15Z 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
[15875]159    Transition(
160        transition_id = 'reset6',
161        title = _('Reset application to submitted'),
162        msg = _('Application reset'),
163        source = PROCESSED,
164        destination = SUBMITTED),
165
[6353]166    )
[6300]167
[7819]168application_workflow = KofaWorkflow(APPLICATION_TRANSITIONS)
[6295]169
[6349]170class ApplicationWorkflowState(WorkflowState, grok.Adapter):
[6295]171    """An adapter to adapt Applicant objects to workflow states.
172    """
173    grok.context(IApplicantBaseData)
174    grok.provides(IWorkflowState)
[6316]175
[6349]176    state_key = 'wf.application.state'
177    state_id = 'wf.application.id'
178
[7819]179class ApplicationWorkflowInfo(KofaWorkflowInfo, grok.Adapter):
[6295]180    """Adapter to adapt Applicant objects to workflow info objects.
181    """
182    grok.context(IApplicantBaseData)
[7819]183    grok.provides(IKofaWorkflowInfo)
[6318]184
[6349]185    def __init__(self, context):
186        self.context = context
187        self.wf = application_workflow
[6318]188
189@grok.subscribe(IApplicantBaseData, IWorkflowTransitionEvent)
190def handle_applicant_transition_event(obj, event):
[11794]191    """Append message to applicant history and lock form
192    when transition happened.
[6318]193    """
[7687]194    msg = event.transition.user_data['msg']
[8312]195    if event.transition.transition_id == 'create':
196        msg += ' (%s)' % obj.student_id
[9398]197        obj.locked = True
198    if event.transition.transition_id == 'submit':
199        obj.locked = True
[6339]200    history = IObjectHistory(obj)
201    history.addMessage(msg)
[6644]202    # In some tests we don't have a an applicants root or a user
[8335]203    try:
204        applicants_root = grok.getSite()['applicants']
205        applicants_root.logger.info('%s - %s' % (obj.applicant_id,msg))
206    except (TypeError, AttributeError):
207        pass
[6318]208    return
Note: See TracBrowser for help on using the repository browser.