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

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

Add studentbasemanagepage which allows performing transitions. Add tests.

  • Property svn:keywords set to Id
File size: 2.0 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
10
11CREATED = 'created'
12ADMITTED = 'admitted'
13
14REGISTRATION_TRANSITIONS = (
15    Transition(
16        transition_id = 'create',
17        title = 'Create student',
18        source = None,
19        condition = NullCondition,
20        msg = 'Student record created',
21        destination = CREATED),
22
23    Transition(
24        transition_id = 'admit',
25        title = 'Admit student',
26        msg = 'Student admitted',
27        source = CREATED,
28        destination = ADMITTED),
29
30    Transition(
31        transition_id = 'reset1',
32        title = 'Reset student',
33        msg = 'Student record reset',
34        source = ADMITTED,
35        destination = CREATED),
36    )
37
38registration_workflow = WAeUPWorkflow(REGISTRATION_TRANSITIONS)
39
40class RegistrationWorkflowState(WorkflowState, grok.Adapter):
41    """An adapter to adapt Student objects to workflow states.
42    """
43    grok.context(IStudent)
44    grok.provides(IWorkflowState)
45
46    state_key = 'wf.registration.state'
47    state_id = 'wf.registration.id'
48
49class RegistrationWorkflowInfo(WAeUPWorkflowInfo, grok.Adapter):
50    """Adapter to adapt Student objects to workflow info objects.
51    """
52    grok.context(IStudent)
53    grok.provides(IWAeUPWorkflowInfo)
54
55    def __init__(self, context):
56        self.context = context
57        self.wf = registration_workflow
58
59@grok.subscribe(IStudent, IWorkflowTransitionEvent)
60def handle_student_transition_event(obj, event):
61    """Append message to student history when transition happened.
62    """
63    msg = '%s' % event.transition.user_data['msg']
64    history = IObjectHistory(obj)
65    history.addMessage(msg)
66    return
Note: See TracBrowser for help on using the repository browser.