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

Last change on this file since 7126 was 7063, checked in by uli, 13 years ago

Merge changes from branch ulif-extimgstore back into trunk.
Beside external image storage also waeupdocs should work again.

  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1"""Workflow for applicants.
2"""
3import grok
4from hurry.workflow.workflow import Transition, WorkflowState, NullCondition
5from hurry.workflow.interfaces import IWorkflowState, IWorkflowTransitionEvent
6from waeup.sirp.applicants.interfaces import IApplicantBaseData
7from waeup.sirp.interfaces import IObjectHistory, IWAeUPWorkflowInfo
8from waeup.sirp.workflow import WAeUPWorkflow, WAeUPWorkflowInfo
9from waeup.sirp.utils.helpers import get_current_principal
10
11INITIALIZED = 'initialized'
12STARTED = 'started'
13SUBMITTED = 'submitted'
14ADMITTED = 'admitted'
15NOT_ADMITTED = 'not admitted'
16CREATED = 'created'
17
18APPLICATION_TRANSITIONS = (
19    Transition(
20        transition_id = 'init',
21        title = 'Initialize application',
22        source = None,
23        condition = NullCondition,
24        msg = 'Application initialized',
25        destination = INITIALIZED),
26
27    Transition(
28        transition_id = 'start',
29        title = 'Start application',
30        msg = 'Application started',
31        source = INITIALIZED,
32        destination = STARTED),
33
34    Transition(
35        transition_id = 'submit',
36        title = 'Submit application',
37        msg = 'Application submitted',
38        source = STARTED,
39        destination = SUBMITTED),
40
41    Transition(
42        transition_id = 'admit',
43        title = 'Admit applicant',
44        msg = 'Applicant admitted',
45        source = SUBMITTED,
46        destination = ADMITTED),
47
48    Transition(
49        transition_id = 'refuse1',
50        title = 'Refuse application',
51        msg = 'Application refused',
52        source = SUBMITTED,
53        destination = NOT_ADMITTED),
54
55    Transition(
56        transition_id = 'refuse2',
57        title = 'Refuse application',
58        msg = 'Application refused',
59        source = ADMITTED,
60        destination = NOT_ADMITTED),
61
62    Transition(
63        transition_id = 'create',
64        title = 'Create student record',
65        msg = 'Student record created',
66        source = ADMITTED,
67        destination = CREATED),
68
69    Transition(
70        transition_id = 'reset1',
71        title = 'Reset application',
72        msg = 'Application reset',
73        source = SUBMITTED,
74        destination = STARTED),
75
76    Transition(
77        transition_id = 'reset2',
78        title = 'Reset application',
79        msg = 'Application reset',
80        source = ADMITTED,
81        destination = STARTED),
82
83    Transition(
84        transition_id = 'reset3',
85        title = 'Reset application',
86        msg = 'Application reset',
87        source = NOT_ADMITTED,
88        destination = STARTED),
89
90    Transition(
91        transition_id = 'reset4',
92        title = 'Reset application',
93        msg = 'Application reset',
94        source = CREATED,
95        destination = STARTED),
96    )
97
98application_workflow = WAeUPWorkflow(APPLICATION_TRANSITIONS)
99
100class ApplicationWorkflowState(WorkflowState, grok.Adapter):
101    """An adapter to adapt Applicant objects to workflow states.
102    """
103    grok.context(IApplicantBaseData)
104    grok.provides(IWorkflowState)
105
106    state_key = 'wf.application.state'
107    state_id = 'wf.application.id'
108
109class ApplicationWorkflowInfo(WAeUPWorkflowInfo, grok.Adapter):
110    """Adapter to adapt Applicant objects to workflow info objects.
111    """
112    grok.context(IApplicantBaseData)
113    grok.provides(IWAeUPWorkflowInfo)
114
115    def __init__(self, context):
116        self.context = context
117        self.wf = application_workflow
118
119@grok.subscribe(IApplicantBaseData, IWorkflowTransitionEvent)
120def handle_applicant_transition_event(obj, event):
121    """Append message to applicant history when transition happened.
122    """
123    msg = '%s' % event.transition.user_data['msg']
124    history = IObjectHistory(obj)
125    history.addMessage(msg)
126    # In some tests we don't have a an applicants root or a user
127    try:
128        user = get_current_principal()
129        applicants_root = grok.getSite()['applicants']
130        applicants_root.logger.info('%s - %s - %s' % (user.id,obj.access_code,msg))
131    except (TypeError, AttributeError):
132        pass
133    return
Note: See TracBrowser for help on using the repository browser.