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

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

Protect pdf download if document has not been published.

Add workflow transition 'retract'.

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