source: main/waeup.kofa/trunk/src/waeup/kofa/workflow.py @ 8755

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

KOFA -> Kofa

  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1## $Id: workflow.py 7819 2012-03-08 22:28:46Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""Workflow components of general use.
19"""
20import grok
21from hurry.workflow.interfaces import IWorkflow, MANUAL, InvalidTransitionError
22from hurry.workflow.workflow import (
23    Transition, Workflow, WorkflowVersions, WorkflowInfo,
24    NullCondition, nullCheckPermission)
25from zope.security.interfaces import NoInteraction
26from zope.security.management import getInteraction
27from waeup.kofa.interfaces import IKofaWorkflowInfo
28
29class KofaWorkflow(Workflow):
30    """A :mod:`hurry.workflow` workflow with more appropriate error
31       messages.
32    """
33    grok.provides(IWorkflow)
34
35    def getTransition(self, source, transition_id):
36        transition = self._id_transitions[transition_id]
37        if transition.source != source:
38            raise InvalidTransitionError(
39                "Transition '%s' requires '%s' as source state (is: '%s')" % (
40                    transition_id, transition.source, source))
41        return transition
42
43
44class WorkflowNullVersions(WorkflowVersions):
45    """A workflow versions manager that does not handle versions.
46
47    Sounds odd, but the default implementation of
48    :class:`hurry.workflow.workflow.WorkflowVersions` is a base
49    implementation that raises :exc:`NotImplemented` exceptions for
50    most of the methods defined below.
51
52    If we want to register a versionless workflow, an utility
53    implementing IWorkflowVersions is looked up nevertheless by
54    WorkflowInfo and WorkflowState components so we **have** to
55    provide workflow versions, even if we do not support versioned
56    workflows.
57
58    This implementation returns empty result sets for any requests,
59    but does not raise :exc:`NotImplemented`.
60    """
61    def getVersions(self, state, id):
62        return []
63
64    def getVersionsWithAutomaticTransitions(self):
65        return []
66
67    def hasVersion(self, id, state):
68        return False
69
70    def hasVersionId(self, id):
71        return False
72
73class KofaWorkflowInfo(WorkflowInfo):
74    """A workflow info that provides a convenience transition getter.
75    """
76
77    grok.provides(IKofaWorkflowInfo)
78
79    def getManualTransitions(self):
80        """Get allowed manual transitions.
81
82        Get a sorted list of tuples containing the `transition_id` and
83        `title` of each allowed transition.
84        """
85        try:
86            checkPermission = getInteraction().checkPermission
87        except NoInteraction:
88            checkPermission = nullCheckPermission
89        return [(transition.transition_id, transition.title)
90                for transition in sorted(self._getTransitions(MANUAL))
91                if transition.condition(self, self.context) and
92                checkPermission(transition.permission, self.context)]
Note: See TracBrowser for help on using the repository browser.