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

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

Translate accesscode workflow.

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