source: main/waeup.sirp/trunk/src/waeup/sirp/students/workflow.py @ 6721

Last change on this file since 6721 was 6720, checked in by Henrik Bettermann, 14 years ago

Fire transition start_clearance and unlock the clearance form when pressing the Start button.

Extend student workflow.

  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1"""Workflow for students.
2"""
3import grok
4from datetime import datetime
5from hurry.workflow.workflow import Transition, WorkflowState, NullCondition
6from hurry.workflow.interfaces import IWorkflowState, IWorkflowTransitionEvent
7from waeup.sirp.students.interfaces import IStudent
8from waeup.sirp.interfaces import IObjectHistory, IWAeUPWorkflowInfo
9from waeup.sirp.workflow import WAeUPWorkflow, WAeUPWorkflowInfo
10from waeup.sirp.utils.helpers import get_current_principal
11
12CREATED = 'created'
13ADMITTED = 'admitted'
14CLEARANCE = 'clearance'
15REQUESTED = 'requested'
16CLEARED = 'cleared'
17
18REGISTRATION_TRANSITIONS = (
19    Transition(
20        transition_id = 'create',
21        title = 'Create student',
22        source = None,
23        condition = NullCondition,
24        msg = 'Student record created',
25        destination = CREATED),
26
27    Transition(
28        transition_id = 'admit',
29        title = 'Admit student',
30        msg = 'Student admitted',
31        source = CREATED,
32        destination = ADMITTED),
33
34    Transition(
35        transition_id = 'reset1',
36        title = 'Reset student',
37        msg = 'Student record reset',
38        source = ADMITTED,
39        destination = CREATED),
40
41    Transition(
42        transition_id = 'start_clearance',
43        title = 'Start clearance',
44        msg = 'Clearance started',
45        source = ADMITTED,
46        destination = CLEARANCE),
47
48    Transition(
49        transition_id = 'reset2',
50        title = 'Reset to admitted',
51        msg = 'Student record reset to admitted',
52        source = CLEARANCE,
53        destination = ADMITTED),
54
55    Transition(
56        transition_id = 'request_clearance',
57        title = 'Request clearance',
58        msg = 'Clearance requested',
59        source = CLEARANCE,
60        destination = REQUESTED),
61
62    Transition(
63        transition_id = 'reset3',
64        title = 'Reset to clearance',
65        msg = 'Student record reset to clearance',
66        source = REQUESTED,
67        destination = CLEARANCE),
68
69    Transition(
70        transition_id = 'clear',
71        title = 'Clear student',
72        msg = 'Cleared',
73        source = REQUESTED,
74        destination = CLEARED),
75
76    Transition(
77        transition_id = 'reset4',
78        title = 'Reset to clearance',
79        msg = 'Student record reset to clearance',
80        source = CLEARED,
81        destination = CLEARANCE),
82    )
83
84
85registration_workflow = WAeUPWorkflow(REGISTRATION_TRANSITIONS)
86
87class RegistrationWorkflowState(WorkflowState, grok.Adapter):
88    """An adapter to adapt Student objects to workflow states.
89    """
90    grok.context(IStudent)
91    grok.provides(IWorkflowState)
92
93    state_key = 'wf.registration.state'
94    state_id = 'wf.registration.id'
95
96class RegistrationWorkflowInfo(WAeUPWorkflowInfo, grok.Adapter):
97    """Adapter to adapt Student objects to workflow info objects.
98    """
99    grok.context(IStudent)
100    grok.provides(IWAeUPWorkflowInfo)
101
102    def __init__(self, context):
103        self.context = context
104        self.wf = registration_workflow
105
106@grok.subscribe(IStudent, IWorkflowTransitionEvent)
107def handle_student_transition_event(obj, event):
108    """Append message to student history and log file when transition happened.
109    """
110    msg = '%s' % event.transition.user_data['msg']
111    history = IObjectHistory(obj)
112    history.addMessage(msg)
113    # In some tests we don't have a students container or a user
114    try:
115        user = get_current_principal()
116        students_container = grok.getSite()['students']
117        students_container.logger.info('%s - %s - %s' % (user.id,obj.student_id,msg))
118    except (TypeError, AttributeError):
119        pass
120    return
Note: See TracBrowser for help on using the repository browser.