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

Last change on this file since 5404 was 4920, checked in by uli, 15 years ago

Make unit tests run again with the new package layout.

File size: 3.2 KB
Line 
1"""Workflows used in the WAeUP SRP portal.
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.interfaces import IWAeUPObject
10
11UNCHECKED = 'unchecked'
12CHECKED = 'checked'
13
14def create_workflow():
15    init_transition = Transition(
16        transition_id = 'init',
17        title = 'Initialize',
18        source = None,
19        condition = NullCondition,
20        destination = UNCHECKED)
21
22    check_transition = Transition(
23        transition_id = 'check',
24        title = 'Check',
25        source = UNCHECKED,
26        destination = CHECKED)
27
28    final_transition = Transition(
29        transition_id = 'finalize',
30        title = 'Delete',
31        source = CHECKED,
32        destination = None)
33
34    return [init_transition, check_transition, final_transition]
35
36
37class WAeUPWorkflow(Workflow):
38    """A hurry.workflow Workflow with more appropriate error messages.
39    """
40    grok.provides(IWorkflow)
41    def __init__(self):
42        super(Workflow, self).__init__()
43        self.refresh(create_workflow())
44
45    def getTransition(self, source, transition_id):
46        from hurry.workflow.interfaces import\
47            InvalidTransitionError, ConditionFailedError
48
49        transition = self._id_transitions[transition_id]
50        if transition.source != source:
51            raise InvalidTransitionError(
52                "Transition '%s' requires '%s' as source state (is: '%s')" % (
53                    transition_id, transition.source, source))
54        return transition
55
56
57class WorkflowNullVersions(WorkflowVersions):
58    """A workflow versions manager that does not handle versions.
59
60    Sounds odd, but the default implementation of
61    :class:`hurry.workflow.workflow.WorkflowVersions` is a base
62    implementation that raises :exc:`NotImplemented` exceptions for
63    most of the methods defined below.
64
65    If we want to register a versionless workflow, an utility
66    implementing IWorkflowVersions is looked up nevertheless by
67    WorkflowInfo and WorkflowState components so we **have** to
68    provide workflow versions, even if we do not support versioned
69    workflows.
70
71    This implementation returns empty result sets for any requests,
72    but does not raise :exc:`NotImplemented`.
73    """
74    def getVersions(self, state, id):
75        return []
76
77    def getVersionsWithAutomaticTransitions(self):
78        return []
79
80    def hasVersion(self, id, state):
81        return False
82
83    def hasVersionId(self, id):
84        return False
85
86# Register global utilities for workflows and workflow versions...
87grok.global_utility(WAeUPWorkflow, IWorkflow)
88grok.global_utility(WorkflowNullVersions, IWorkflowVersions)
89
90class WorkflowState(grok.Adapter, WorkflowState):
91    """An adapter to adapt WAeUP objects to workflow states.
92    """
93    grok.context(IWAeUPObject)
94    grok.provides(IWorkflowState)
95   
96class WorkflowInfo(grok.Adapter, WorkflowInfo):
97    """Adapter to adapt WAeUP objects to workflow info objects.
98    """
99    grok.context(IWAeUPObject)
100    grok.provides(IWorkflowInfo)
Note: See TracBrowser for help on using the repository browser.