[Zope3-checkins] CVS: Packages3/workflow/browser/stateful - filteradapter.py:1.1 interfaces.py:1.1 configure.zcml:1.8

Christian Theune ct@gocept.com
Thu, 27 Mar 2003 09:54:25 -0500


Update of /cvs-repository/Packages3/workflow/browser/stateful
In directory cvs.zope.org:/tmp/cvs-serv23591/stateful

Modified Files:
	configure.zcml 
Added Files:
	filteradapter.py interfaces.py 
Log Message:
 - refactored the workflow filter as an adapter


=== Added File Packages3/workflow/browser/stateful/filteradapter.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.
#
##############################################################################
"""filtering view for ProcessInstances of a stateful workflow
 
$Id: filteradapter.py,v 1.1 2003/03/27 14:54:24 ctheune Exp $
"""
__metaclass__ = type

from zope.component import queryAdapter 
from zope.app.interfaces.workflow import IProcessInstanceContainerAdaptable
from zope.app.interfaces.workflow import IProcessInstanceContainer
from interfaces import IContentFilterAdapter

class FilterAdapter:
    
    __used_for__ = IProcessInstanceContainerAdaptable
    __implements__ = IContentFilterAdapter

    def __init__(self, context):
        self.context = context

    def filterByState(self, objList, state, workflow='default'):
        """See IContentFilterAdapter"""
        res = []

        for obj in objList:
            adapter = queryAdapter(obj, IProcessInstanceContainer)
            if adapter:
                for item in adapter.values():
                    if item.processDefinitionName != workflow:
                        continue
                    if item.status == state:
                        res.append(obj)
                        break
        return res





=== Added File Packages3/workflow/browser/stateful/interfaces.py ===
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""Interfaces for stateful workflow.

$Id: interfaces.py,v 1.1 2003/03/27 14:54:24 ctheune Exp $
"""

from zope.interface import Interface

class IContentFilterAdapter(Interface):

    def filterByState(objList, state, workflow='default'):
        """Filter a list of objects according to given workflow and state

        objList  ... list of objects
        state    ... name of a state (of the given workflow) in which the result
                      objects must be
        workflow ... name of a workflow to which result objects must be attached
        """


=== Packages3/workflow/browser/stateful/configure.zcml 1.7 => 1.8 ===
--- Packages3/workflow/browser/stateful/configure.zcml:1.7	Wed Mar 26 14:41:02 2003
+++ Packages3/workflow/browser/stateful/configure.zcml	Thu Mar 27 09:54:24 2003
@@ -179,6 +179,10 @@
   <browser:page name="published_content.html" attribute="published_content" />
 </browser:pages>
 
-
+<adapter
+    factory=".filteradapter.FilterAdapter"
+    provides=".interfaces.IContentFilterAdapter"
+    for="zope.app.interfaces.container.IContentContainer"
+    permission="zope.View" />       <!-- XXX is this permission right? -->
 
 </zopeConfigure>