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

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

Propset svn:keywords "Id"

  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1## $Id: workflow.py 12438 2015-01-11 08:27:37Z 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"""
20
21import grok
22from zope.component import getUtility
23from hurry.workflow.workflow import Transition, WorkflowState, NullCondition
24from hurry.workflow.interfaces import (
25    IWorkflowState, IWorkflowTransitionEvent, InvalidTransitionError)
26from waeup.kofa.interfaces import (
27    IObjectHistory, IKofaWorkflowInfo,
28    SimpleKofaVocabulary)
29from waeup.kofa.interfaces import MessageFactory as _
30from waeup.kofa.workflow import KofaWorkflow, KofaWorkflowInfo
31from waeup.kofa.documents.interfaces import IPublicDocument
32
33CREATED = 'created'
34PUBLISHED = 'published'
35
36PUBLISHING_TRANSITIONS = (
37    Transition(
38        transition_id = 'create',
39        title = _('Create document'),
40        source = None,
41        condition = NullCondition,
42        msg = _('Document created'),
43        destination = CREATED),
44
45    Transition(
46        transition_id = 'publish',
47        title = _('Publish document'),
48        source = CREATED,
49        condition = NullCondition,
50        msg = _('Document published'),
51        destination = PUBLISHED),
52
53    Transition(
54        transition_id = 'retract',
55        title = _('Retract documet'),
56        source = PUBLISHED,
57        condition = NullCondition,
58        msg = _('Document retracted'),
59        destination = CREATED),
60    )
61
62publishing_workflow = KofaWorkflow(PUBLISHING_TRANSITIONS)
63
64class PublishingWorkflowState(WorkflowState, grok.Adapter):
65    """An adapter to adapt Document objects to workflow states.
66    """
67    grok.context(IPublicDocument)
68    grok.provides(IWorkflowState)
69
70    state_key = 'wf.publishing.state'
71    state_id = 'wf.publishing.id'
72
73
74class PublishingWorkflowInfo(KofaWorkflowInfo, grok.Adapter):
75    """Adapter to adapt CustomerDocument objects to workflow info objects.
76    """
77    grok.context(IPublicDocument)
78    grok.provides(IKofaWorkflowInfo)
79
80    def __init__(self, context):
81        self.context = context
82        self.wf = publishing_workflow
83
84
85@grok.subscribe(IPublicDocument, IWorkflowTransitionEvent)
86def handle_public_document_transition_event(obj, event):
87    """Append message to document history and log file.
88
89    """
90    msg = event.transition.user_data['msg']
91    history = IObjectHistory(obj)
92    history.addMessage(msg)
93    try:
94        grok.getSite().logger.info('%s - %s' % (obj.document_id, msg))
95    except (TypeError, AttributeError):
96        pass
97    return
Note: See TracBrowser for help on using the repository browser.