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

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

Add first browser test.

  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1## $Id: workflow.py 12222 2014-12-14 06:20:40Z 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    Transition(
44        transition_id = 'publish',
45        title = _('Publish document'),
46        source = CREATED,
47        condition = NullCondition,
48        msg = _('Document published'),
49        destination = PUBLISHED),
50    )
51
52publishing_workflow = IkobaWorkflow(PUBLISHING_TRANSITIONS)
53
54class PublishingWorkflowState(WorkflowState, grok.Adapter):
55    """An adapter to adapt Document objects to workflow states.
56    """
57    grok.context(IPublicDocument)
58    grok.provides(IWorkflowState)
59
60    state_key = 'wf.publishing.state'
61    state_id = 'wf.publishing.id'
62
63
64class PublishingWorkflowInfo(IkobaWorkflowInfo, grok.Adapter):
65    """Adapter to adapt CustomerDocument objects to workflow info objects.
66    """
67    grok.context(IPublicDocument)
68    grok.provides(IIkobaWorkflowInfo)
69
70    def __init__(self, context):
71        self.context = context
72        self.wf = publishing_workflow
73
74
75@grok.subscribe(IPublicDocument, IWorkflowTransitionEvent)
76def handle_public_document_transition_event(obj, event):
77    """Append message to document history and log file.
78
79    """
80    msg = event.transition.user_data['msg']
81    history = IObjectHistory(obj)
82    history.addMessage(msg)
83    try:
84        grok.getSite().logger.info('%s - %s' % (obj.document_id, msg))
85    except (TypeError, AttributeError):
86        pass
87    return
Note: See TracBrowser for help on using the repository browser.