source: main/waeup.ikoba/trunk/src/waeup/ikoba/documents/workflow.py @ 12213

Last change on this file since 12213 was 12213, checked in by Henrik Bettermann, 10 years ago

We need different workflows for customer documents and central 'public' documents.

  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1## $Id: workflow.py 12213 2014-12-13 10:51:17Z henrik $
2##
3## Copyright (C) 2014 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 for documents.
19"""
20import grok
21from zope.component import getUtility
22from hurry.workflow.workflow import Transition, WorkflowState, NullCondition
23from hurry.workflow.interfaces import (
24    IWorkflowState, IWorkflowTransitionEvent, InvalidTransitionError)
25from waeup.ikoba.interfaces import (
26    IObjectHistory, IIkobaWorkflowInfo,
27    SimpleIkobaVocabulary,
28    CREATED, PUBLISHED)
29from waeup.ikoba.interfaces import MessageFactory as _
30from waeup.ikoba.workflow import IkobaWorkflow, IkobaWorkflowInfo
31from waeup.ikoba.documents.interfaces import IPublicDocument
32
33
34PUBLISHING_TRANSITIONS = (
35    Transition(
36        transition_id = 'create',
37        title = _('Create document'),
38        source = None,
39        condition = NullCondition,
40        msg = _('Document created'),
41        destination = CREATED),
42    )
43
44publishing_workflow = IkobaWorkflow(PUBLISHING_TRANSITIONS)
45
46class PublishingWorkflowState(WorkflowState, grok.Adapter):
47    """An adapter to adapt Document objects to workflow states.
48    """
49    grok.context(IPublicDocument)
50    grok.provides(IWorkflowState)
51
52    state_key = 'wf.publishing.state'
53    state_id = 'wf.publishing.id'
54
55
56class PublishingWorkflowInfo(IkobaWorkflowInfo, grok.Adapter):
57    """Adapter to adapt CustomerDocument objects to workflow info objects.
58    """
59    grok.context(IPublicDocument)
60    grok.provides(IIkobaWorkflowInfo)
61
62    def __init__(self, context):
63        self.context = context
64        self.wf = publishing_workflow
65
66
67@grok.subscribe(IPublicDocument, IWorkflowTransitionEvent)
68def handle_public_document_transition_event(obj, event):
69    """Append message to document history and log file.
70
71    """
72    msg = event.transition.user_data['msg']
73    history = IObjectHistory(obj)
74    history.addMessage(msg)
75    try:
76        grok.getSite().logger.info('%s' % msg)
77    except (TypeError, AttributeError):
78        pass
79    return
Note: See TracBrowser for help on using the repository browser.