## $Id: workflow.py 7250 2011-12-02 12:46:36Z henrik $ ## ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """Workflow for applicants. """ import grok from hurry.workflow.workflow import Transition, WorkflowState, NullCondition from hurry.workflow.interfaces import IWorkflowState, IWorkflowTransitionEvent from waeup.sirp.applicants.interfaces import IApplicantBaseData from waeup.sirp.interfaces import IObjectHistory, IWAeUPWorkflowInfo from waeup.sirp.workflow import WAeUPWorkflow, WAeUPWorkflowInfo from waeup.sirp.utils.helpers import get_current_principal INITIALIZED = 'initialized' STARTED = 'started' PAID = 'paid' SUBMITTED = 'submitted' ADMITTED = 'admitted' NOT_ADMITTED = 'not admitted' CREATED = 'created' APPLICATION_TRANSITIONS = ( Transition( transition_id = 'init', title = 'Initialize application', source = None, condition = NullCondition, msg = 'Application initialized', destination = INITIALIZED), Transition( transition_id = 'start', title = 'Start application', msg = 'Application started', source = INITIALIZED, destination = STARTED), Transition( transition_id = 'pay', title = 'Pay acceptance fee', msg = 'Fee paid', source = STARTED, destination = PAID), Transition( transition_id = 'submit', title = 'Submit application', msg = 'Application submitted', source = PAID, destination = SUBMITTED), Transition( transition_id = 'admit', title = 'Admit applicant', msg = 'Applicant admitted', source = SUBMITTED, destination = ADMITTED), Transition( transition_id = 'refuse1', title = 'Refuse application', msg = 'Application refused', source = SUBMITTED, destination = NOT_ADMITTED), Transition( transition_id = 'refuse2', title = 'Refuse application', msg = 'Application refused', source = ADMITTED, destination = NOT_ADMITTED), Transition( transition_id = 'create', title = 'Create student record', msg = 'Student record created', source = ADMITTED, destination = CREATED), Transition( transition_id = 'reset1', title = 'Reset application to started', msg = 'Application reset', source = SUBMITTED, destination = STARTED), Transition( transition_id = 'reset2', title = 'Reset application to started', msg = 'Application reset', source = ADMITTED, destination = STARTED), Transition( transition_id = 'reset3', title = 'Reset application to started', msg = 'Application reset', source = NOT_ADMITTED, destination = STARTED), Transition( transition_id = 'reset4', title = 'Reset application to started', msg = 'Application reset', source = CREATED, destination = STARTED), Transition( transition_id = 'reset5', title = 'Reset application to paid', msg = 'Application reset', source = SUBMITTED, destination = PAID), ) application_workflow = WAeUPWorkflow(APPLICATION_TRANSITIONS) class ApplicationWorkflowState(WorkflowState, grok.Adapter): """An adapter to adapt Applicant objects to workflow states. """ grok.context(IApplicantBaseData) grok.provides(IWorkflowState) state_key = 'wf.application.state' state_id = 'wf.application.id' class ApplicationWorkflowInfo(WAeUPWorkflowInfo, grok.Adapter): """Adapter to adapt Applicant objects to workflow info objects. """ grok.context(IApplicantBaseData) grok.provides(IWAeUPWorkflowInfo) def __init__(self, context): self.context = context self.wf = application_workflow @grok.subscribe(IApplicantBaseData, IWorkflowTransitionEvent) def handle_applicant_transition_event(obj, event): """Append message to applicant history when transition happened. """ msg = '%s' % event.transition.user_data['msg'] history = IObjectHistory(obj) history.addMessage(msg) # In some tests we don't have a an applicants root or a user try: user = get_current_principal() applicants_root = grok.getSite()['applicants'] applicants_root.logger.info('%s - %s - %s' % (user.id,obj.access_code,msg)) except (TypeError, AttributeError): pass return