[Zope-CVS] CVS: Packages3/workflow/browser/stateful - do_transitions.pt:1.1 filterTest.pt:1.1 instance.py:1.1 view.py:1.1 configure.zcml:1.4
Michael Howitz
mh+zope@gocept.com
Wed, 26 Mar 2003 10:24:58 -0500
Update of /cvs-repository/Packages3/workflow/browser/stateful
In directory cvs.zope.org:/tmp/cvs-serv26142/browser/stateful
Modified Files:
configure.zcml
Added Files:
do_transitions.pt filterTest.pt instance.py view.py
Log Message:
new view for stateful workflow (to do transitions)
=== Added File Packages3/workflow/browser/stateful/do_transitions.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
<style metal:fill-slot="headers" type="text/css"></style>
</head>
<body>
<div metal:fill-slot="body">
<div metal:define-macro="contents">
<div metal:define-macro="contents_selectWorkflow"
tal:define="workFlow request/workFlow | nothing">
<div tal:condition="not:workFlow" tal:omit-tag="">
<form name="containerContentsForm" method="get" action="@@workflows.html"
tal:define="container_contents view/listContentInfo"
tal:condition="container_contents">
Workflow:
<select name="workFlow" size="1">
<option tal:repeat="workflow container_contents"
tal:attributes="value workflow/id"
tal:content="workflow/name"></option>
</select>
<input type="submit" value="choose" />
</form>
</div>
<div tal:condition="workFlow" tal:omit-tag="">
Workflow: <div tal:replace="view/getWorkFlowTitle"></div>
</div>
</div>
<div metal:define-macro="contents_changeState">
</div>
</div>
<br/>
<div metal:define-macro="contents_transitions"
tal:define="info view/getTransitions">
Current Status: <div tal:replace="info/status"/>
<br/>
Possible State Changes:
<form action="@@fireTransition.html" method="get">
<input type="hidden" name="workFlow" tal:attributes="value request/workFlow | nothing">
<div tal:repeat="trans info/transitions"
tal:condition="info/transitions | nothing"
tal:omit-tag="">
<input type="radio"
name="selTransition"
tal:attributes="value trans/name"/> <span tal:replace="trans/title"/><br/>
</div>
<input type="submit" value="do it">
</form>
</div>
</div>
</body>
</html>
=== Added File Packages3/workflow/browser/stateful/filterTest.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
<style metal:fill-slot="headers" type="text/css"></style>
</head>
<body>
<div metal:fill-slot="body">
<div tal:repeat="obj view/filterTest"
tal:omit-tag="">
<div tal:replace="obj"/><br/>
</div>
</div>
</body>
</html>
=== Added File Packages3/workflow/browser/stateful/instance.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.
#
##############################################################################
"""ProcessInstance views for a stateful workflow
$Id: instance.py,v 1.1 2003/03/26 15:24:27 icemac Exp $
"""
__metaclass__ = type
from zope.schema import getFieldNames
from zope.component import queryView, queryAdapter, getAdapter, getService
from zope.app.services.servicenames import Workflows
from zope.publisher.browser import BrowserView
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.app.interfaces.workflow import IProcessInstanceContainerAdaptable
from zope.app.interfaces.workflow import IProcessInstanceContainer
from zope.app.interfaces.workflow.stateful import IStatefulProcessInstance
from zope.app.interfaces.dublincore import IZopeDublinCore
from zope.proxy.introspection import removeAllProxies
class StatefulInstanceContainerView(BrowserView):
__used_for__ = IProcessInstanceContainerAdaptable
def _extractContentInfo(self, item):
id, processInstance = item
info = {}
info['id'] =id
info['name']=self._getTitle(self._getProcessDefinition(processInstance))
return info
def listContentInfo(self):
return map(self._extractContentInfo,
getAdapter(self.context, IProcessInstanceContainer).items())
def _getTitle(self, obj):
return getAdapter(obj, IZopeDublinCore).Title()
contents = ViewPageTemplateFile('do_transitions.pt')
contentsMacros = contents
def getWorkFlowTitle(self):
return self._getTitle(
self._getProcessDefinition(
self._getSelWorkflow()))
def _getSelWorkflow(self):
reqWorkflow = self.request.get('workFlow', u'')
adapter = getAdapter(self.context, IProcessInstanceContainer)
if reqWorkflow is u'':
pi = adapter[adapter.keys()[0]]
else:
pi = adapter[reqWorkflow]
return pi
def _getProcessDefinition(self, processInstance):
ws = getService(self.context, Workflows)
return ws.getProcessDefinition(processInstance.processDefinitionName)
def getTransitions(self):
info = {}
pi = self._getSelWorkflow()
info['status'] = pi.status
if IStatefulProcessInstance.isImplementedBy(pi):
pd = self._getProcessDefinition(pi)
# XXX do we really want to do that?
clean_pd = removeAllProxies(pd)
transition_names = pi.getOutgoingTransitions()
trans_info = []
print transition_names
for name in transition_names:
transition = clean_pd.getTransition(name)
adapter = getAdapter(transition, IZopeDublinCore)
trans_info.append({'name':name, 'title': adapter.Title()})
info['transitions'] = trans_info
return info
def fireTransition(self):
pi = self._getSelWorkflow()
trans = self.request.get('selTransition', None)
self.request.response.redirect('@@workflows.html?workFlow=%s' % pi.processDefinitionName)
if pi and trans:
pi.fireTransition(trans)
=== Added File Packages3/workflow/browser/stateful/view.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: view.py,v 1.1 2003/03/26 15:24:27 icemac Exp $
"""
__metaclass__ = type
from zope.component import getAdapter, queryAdapter, getService
from zope.app.services.servicenames import Workflows
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.app.interfaces.workflow import IProcessInstanceContainerAdaptable
from zope.app.interfaces.workflow import IProcessInstanceContainer
from zope.app.interfaces.workflow.stateful import IStatefulProcessInstance
from zope.app.browser.container.contents import Contents
class FilterList(Contents):
__used_for__ = IProcessInstanceContainerAdaptable
def filterByState(self, objList, workflow, state):
"""Filter a list of objects according to given workflow and state
objList ... list of objects
workflow ... name of a workflow to which result objects must be attached
state ... name of a state (of the given workflow) in which the result
objects must be
"""
res = []
for obj in objList:
adapter = queryAdapter(obj['object'], IProcessInstanceContainer)
if adapter:
for wfName,wfItem in adapter.items():
if wfName != workflow:
continue
if wfItem.status == state:
res.append(obj)
break
return res
def _getProcessDefinition(self, processInstance):
ws = getService(self.context, Workflows)
return ws.getProcessDefinition(processInstance.processDefinitionName)
filter = ViewPageTemplateFile('filterTest.pt')
def filterTest(self):
return self.filterByState(self.listContentInfo(), 'default', 'published')
=== Packages3/workflow/browser/stateful/configure.zcml 1.3 => 1.4 ===
--- Packages3/workflow/browser/stateful/configure.zcml:1.3 Fri Feb 7 16:50:52 2003
+++ Packages3/workflow/browser/stateful/configure.zcml Wed Mar 26 10:24:27 2003
@@ -110,4 +110,40 @@
+<!-- ProcessInstanceContainerAdaptable -->
+<browser:pages
+ for="zope.app.interfaces.workflow.IProcessInstanceContainerAdaptable"
+ permission="zope.workflow.UseProcessInstances"
+ class="zope.app.browser.workflow.stateful.instance.StatefulInstanceContainerView">
+
+ <browser:page name="workflows.html" attribute="contents" />
+ <browser:page name="fireTransition.html" attribute="fireTransition" />
+</browser:pages>
+
+<browser:menuItem
+ for="zope.app.interfaces.workflow.IProcessInstanceContainerAdaptable"
+ menu="zmi_views"
+ title="Workflows"
+ action="workflows.html"
+ />
+
+<browser:pages
+ for="zope.app.interfaces.container.IContainer"
+ permission="zope.View"
+ class="zope.app.browser.workflow.stateful.view.FilterList">
+
+ <browser:page name="filter.html" attribute="filter" />
+</browser:pages>
+
+
+<!--
+<browser:pages
+ for="zope.app.interfaces.workflow.IProcessInstanceContainerAdaptable"
+ permission="zope.View"
+ class="zope.app.browser.workflow.stateful.view.FilterList">
+
+ <browser:page name="filter.html" attribute="filter" />
+</browser:pages>
+-->
+
</zopeConfigure>