[CMF-checkins] CVS: CMF/CMFStaging - WorkflowRepository.py:1.1 WorkflowWithRepositoryTool.py:1.1 version.txt:1.1 __init__.py:1.3 tool.gif:1.2

Shane Hathaway shane@cvs.zope.org
Thu, 12 Sep 2002 13:00:54 -0400


Update of /cvs-repository/CMF/CMFStaging
In directory cvs.zope.org:/tmp/cvs-serv25389

Modified Files:
	__init__.py tool.gif 
Added Files:
	WorkflowRepository.py WorkflowWithRepositoryTool.py 
	version.txt 
Log Message:
Added the workflow repository tool and a version of the workflow tool that
uses a workflow repository.


=== Added File CMF/CMFStaging/WorkflowRepository.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""WorkflowRepository class.

$Id: WorkflowRepository.py,v 1.1 2002/09/12 17:00:53 shane Exp $
"""

import os

import Globals
from AccessControl import ClassSecurityInfo
from Products.CMFCore.utils import getToolByName, SimpleItemWithProperties
from Products.CMFCore.CMFCorePermissions import ManagePortal
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from BTrees.OOBTree import OOBTree

_www = os.path.join(os.path.dirname(__file__), 'www')


class WorkflowRepository (SimpleItemWithProperties):
    """An object where a workflow tool stores object status.
    """
    meta_type = 'Workflow Repository'

    security = ClassSecurityInfo()

    manage_options = (
        {'label': 'Info', 'action': 'manage_main'},
        ) + SimpleItemWithProperties.manage_options

    manage_main = PageTemplateFile('workflowRepositoryInfo', _www)

    _properties = ()

    def __init__(self, id):
        self.id = id
        self._histories = OOBTree()

    security.declarePrivate('getHistory')
    def getHistory(self, id):
        return self._histories.get(id)

    security.declarePrivate('setHistory')
    def setHistory(self, id, h):
        self._histories[id] = h

    security.declareProtected(ManagePortal, 'countHistories')
    def countHistories(self):
        return len(self._histories)

Globals.InitializeClass(WorkflowRepository)


manage_addWorkflowRepositoryForm = PageTemplateFile(
    'addWorkflowRepository', _www)

def manage_addWorkflowRepository(dispatcher, id, REQUEST=None):
    """ """
    ob = WorkflowRepository(id)
    dispatcher._setObject(id, ob)
    if REQUEST is not None:
        return dispatcher.manage_main(dispatcher, REQUEST)



=== Added File CMF/CMFStaging/WorkflowWithRepositoryTool.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""WorkflowWithRepositoryTool class.

$Id: WorkflowWithRepositoryTool.py,v 1.1 2002/09/12 17:00:53 shane Exp $
"""

import Globals
from Acquisition import aq_inner, aq_parent
from AccessControl import ClassSecurityInfo
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.WorkflowTool import WorkflowTool
from Persistence import PersistentMapping


class WorkflowWithRepositoryTool (WorkflowTool):
    """Workflow tool that uses a workflow status repository.

    Depends on portal_versions."""

    meta_type = 'Workflow Tool (repository aware)'

    security = ClassSecurityInfo()

    def _getId(self, ob, allow_create_version=0):
        vt = getToolByName(self, 'portal_versions')
        if not vt.isUnderVersionControl(ob):
            if allow_create_version:
                vt.checkin(ob, 'Auto checkin by workflow')
            else:
                return None
        return vt.getHistoryId(ob)

    def _getRepository(self):
        parent = aq_parent(aq_inner(self))
        try:
            repo = parent.workflow_repository
        except AttributeError:
            raise RuntimeError, 'A workflow_repository object is required.'
        return repo

    security.declarePrivate('getHistoryOf')
    def getHistoryOf(self, wf_id, ob):
        """Invoked by workflow definitions.  Returns the history of an object.
        """
        ob_id = self._getId(ob)
        if ob_id is None:
            return ()
        repo = self._getRepository()
        h = repo.getHistory(ob_id)
        if h is None:
            return None
        else:
            return h.get(wf_id, None)

    security.declarePrivate('setStatusOf')
    def setStatusOf(self, wf_id, ob, status):
        """Invoked by workflow definitions.  Appends to the workflow history.
        """
        ob_id = self._getId(ob, 1)
        assert ob_id, 'No version history ID available'
        repo = self._getRepository()
        h = repo.getHistory(ob_id)
        if h is None:
            h = PersistentMapping()
            repo.setHistory(ob_id, h)
        wfh = h.get(wf_id)
        if wfh is not None:
            wfh = list(wfh)
        else:
            wfh = []
        wfh.append(status)
        h[wf_id] = tuple(wfh)

Globals.InitializeClass(WorkflowWithRepositoryTool)



=== Added File CMF/CMFStaging/version.txt ===
Unreleased


=== CMF/CMFStaging/__init__.py 1.2 => 1.3 ===
--- CMF/CMFStaging/__init__.py:1.2	Tue May 14 13:54:53 2002
+++ CMF/CMFStaging/__init__.py	Thu Sep 12 13:00:53 2002
@@ -22,6 +22,7 @@
 from Products.CMFCore import utils
 
 import VersionsTool, StagingTool, LockTool
+import WorkflowRepository, WorkflowWithRepositoryTool
 
 registerDirectory('skins', globals())
 
@@ -29,6 +30,7 @@
     VersionsTool.VersionsTool,
     StagingTool.StagingTool,
     LockTool.LockTool,
+    WorkflowWithRepositoryTool.WorkflowWithRepositoryTool,
     )
 
 this_module = sys.modules[ __name__ ]
@@ -39,4 +41,11 @@
     utils.ToolInit('CMFStaging Tool', tools=tools,
                    product_name='CMFStaging', icon='tool.gif',
                    ).initialize(context)
+
+    context.registerClass(
+        WorkflowRepository.WorkflowRepository,
+        constructors=(WorkflowRepository.manage_addWorkflowRepositoryForm,
+                      WorkflowRepository.manage_addWorkflowRepository),
+        icon='tool.gif',
+        )
 


=== CMF/CMFStaging/tool.gif 1.1.1.1 => 1.2 ===