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

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

Extend application workflow.

  • Property svn:keywords set to Id
File size: 4.9 KB
RevLine 
[6295]1"""Workflow for applicants.
2"""
3import grok
4from hurry.workflow.workflow import Transition, Workflow, WorkflowVersions
5from hurry.workflow.workflow import WorkflowInfo, WorkflowState, NullCondition
6from hurry.workflow.interfaces import MANUAL, AUTOMATIC, SYSTEM
7from hurry.workflow.interfaces import IWorkflow, IWorkflowState, IWorkflowInfo
8from hurry.workflow.interfaces import IWorkflowVersions
9from waeup.sirp.applicants.interfaces import IApplicantBaseData
10
11INITIALIZED = 'initialized'
12STARTED = 'started'
13SUBMITTED = 'submitted'
14ADMITTED = 'admitted'
15NOT_ADMITTED = 'not admitted'
16CREATED = 'created'
17
18def create_workflow():
19    init_transition = Transition(
20        transition_id = 'init',
21        title = 'Initialize',
22        source = None,
23        condition = NullCondition,
24        destination = INITIALIZED)
25
26    start_transition = Transition(
27        transition_id = 'start',
[6300]28        title = 'Start application',
[6295]29        source = INITIALIZED,
30        destination = STARTED)
31
32    submit_transition = Transition(
33        transition_id = 'submit',
[6300]34        title = 'Submit application record',
[6295]35        source = STARTED,
36        destination = SUBMITTED)
37
38    admit_transition = Transition(
39        transition_id = 'admit',
[6300]40        title = 'Admit applicant',
[6295]41        source = SUBMITTED,
42        destination = ADMITTED)
43
[6300]44    refuse1_transition = Transition(
45        transition_id = 'refuse1',
46        title = 'Refuse application',
[6295]47        source = SUBMITTED,
48        destination = NOT_ADMITTED)
49
[6300]50    refuse2_transition = Transition(
51        transition_id = 'refuse2',
52        title = 'Refuse application',
53        source = ADMITTED,
54        destination = NOT_ADMITTED)
55
[6295]56    create_transition = Transition(
57        transition_id = 'create',
58        title = 'Create Student',
59        source = ADMITTED,
60        destination = CREATED)
61
[6300]62    reset1_transition = Transition(
63        transition_id = 'reset1',
64        title = 'Reset application',
65        source = SUBMITTED,
66        destination = STARTED)
[6295]67
[6300]68    reset2_transition = Transition(
69        transition_id = 'reset2',
70        title = 'Reset application',
71        source = ADMITTED,
72        destination = STARTED)
73
74    reset3_transition = Transition(
75        transition_id = 'reset3',
76        title = 'Reset application',
77        source = NOT_ADMITTED,
78        destination = STARTED)
79
80    reset4_transition = Transition(
81        transition_id = 'reset4',
82        title = 'Reset application',
83        source = CREATED,
84        destination = STARTED)
85
[6295]86    return [init_transition, start_transition, submit_transition, admit_transition,
[6300]87         create_transition, refuse1_transition, refuse2_transition, reset1_transition,
88         reset2_transition, reset3_transition, reset4_transition]
[6295]89
90
91class ApplicationWorkflow(Workflow):
92    """A hurry.workflow Workflow with more appropriate error messages.
93    """
94    grok.provides(IWorkflow)
95    def __init__(self):
96        super(Workflow, self).__init__()
97        self.refresh(create_workflow())
98
99    def getTransition(self, source, transition_id):
100        from hurry.workflow.interfaces import\
101            InvalidTransitionError, ConditionFailedError
102
103        transition = self._id_transitions[transition_id]
104        if transition.source != source:
105            raise InvalidTransitionError(
106                "Transition '%s' requires '%s' as source state (is: '%s')" % (
107                    transition_id, transition.source, source))
108        return transition
109
110
111class ApplicationWorkflowNullVersions(WorkflowVersions):
112    """A workflow versions manager that does not handle versions.
113
114    Sounds odd, but the default implementation of
115    :class:`hurry.workflow.workflow.WorkflowVersions` is a base
116    implementation that raises :exc:`NotImplemented` exceptions for
117    most of the methods defined below.
118
119    If we want to register a versionless workflow, an utility
120    implementing IWorkflowVersions is looked up nevertheless by
121    WorkflowInfo and WorkflowState components so we **have** to
122    provide workflow versions, even if we do not support versioned
123    workflows.
124
125    This implementation returns empty result sets for any requests,
126    but does not raise :exc:`NotImplemented`.
127    """
128    def getVersions(self, state, id):
129        return []
130
131    def getVersionsWithAutomaticTransitions(self):
132        return []
133
134    def hasVersion(self, id, state):
135        return False
136
137    def hasVersionId(self, id):
138        return False
139
140# Register global utilities for workflows and workflow versions...
141grok.global_utility(ApplicationWorkflow, IWorkflow)
142grok.global_utility(ApplicationWorkflowNullVersions, IWorkflowVersions)
143
[6300]144class ApplicationState(grok.Adapter, WorkflowState):
[6295]145    """An adapter to adapt Applicant objects to workflow states.
146    """
147    grok.context(IApplicantBaseData)
148    grok.provides(IWorkflowState)
149   
[6300]150class ApplicationInfo(grok.Adapter, WorkflowInfo):
[6295]151    """Adapter to adapt Applicant objects to workflow info objects.
152    """
153    grok.context(IApplicantBaseData)
154    grok.provides(IWorkflowInfo)
Note: See TracBrowser for help on using the repository browser.