provide special views for tracking storage and tracks

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2582 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2008-05-08 14:41:09 +00:00
parent 8582252967
commit 6cce2a4339
4 changed files with 188 additions and 8 deletions

View file

@ -1,5 +1,5 @@
#
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -22,13 +22,16 @@ Ordered container implementation.
$Id$
"""
from zope.app import zapi
from zope.cachedescriptors.property import Lazy
from zope.app.pagetemplate import ViewPageTemplateFile
from zope.app.container.browser.contents import JustContents
from zope.app.i18n import ZopeMessageFactory as _
from zope.cachedescriptors.property import Lazy
from zope.interface import Interface
contents_template = ViewPageTemplateFile('contents.pt')
class ContainerView(JustContents):
def checkMoveAction(self):
@ -38,11 +41,13 @@ class ContainerView(JustContents):
# informations for the ajax.inner.html view (template):
@Lazy
def template(self):
basicView = zapi.getMultiAdapter((self.context, self.request),
Interface, name=u'contents.html')
return basicView.index
template = contents_template
#@Lazy
#def template(self):
# basicView = zapi.getMultiAdapter((self.context, self.request),
# Interface, name=u'contents.html')
# return basicView.index
@Lazy
def macro(self):

View file

@ -134,3 +134,9 @@ We can also mark earlier runs by stopping them.
>>> tracks.getRun(runId=2)
<Run 2, ..., ..., True>
Tracking Views
==============
>>> from cybertools.tracking.browser import TrackingStorageView

94
tracking/browser.py Normal file
View file

@ -0,0 +1,94 @@
#
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
View class(es) for tracking storage and tracks.
$Id$
"""
from zope import component
from zope.app.pagetemplate import ViewPageTemplateFile
from zope.cachedescriptors.property import Lazy
from zope.security.proxy import removeSecurityProxy
from zope.traversing.api import getName
from zope.traversing.browser import absoluteURL
from cybertools.container.base import ContainerView, contents_template
from cybertools.tracking.btree import timeStamp2ISO
tracking_template = ViewPageTemplateFile('tracking.pt')
class TrackingStorageView(ContainerView):
contents_template = contents_template
template = tracking_template
def __call__(self):
return self.template()
def getTracks(self):
for tr in reversed(removeSecurityProxy(self.context.values())):
view = component.queryMultiAdapter((tr, self.request))
if view:
yield view
else:
yield TrackView(tr, self.request)
class TrackView(object):
def __init__(self, context, request):
self.context = context
self.request = request
@Lazy
def id(self):
return getName(self.context)
@Lazy
def url(self):
return absoluteURL(self.context, self.request)
@Lazy
def metadata(self):
return self.context.metadata
@Lazy
def task(self):
return self.metadata['taskId']
taskTitle = task
taskUrl = None
@Lazy
def run(self):
return self.metadata['runId']
@Lazy
def user(self):
return self.metadata['userName']
userTitle = user
userUrl = None
@Lazy
def timeStamp(self):
return timeStamp2ISO(self.metadata['timeStamp'])

75
tracking/tracking.pt Normal file
View file

@ -0,0 +1,75 @@
<html metal:use-macro="context/@@standard_macros/view"
i18n:domain="zope">
<body>
<div metal:fill-slot="body">
<div metal:define-macro="contents"
id="body.contents"
tal:define="content_macros view/contents_template/macros">
<form name="tracks" method="post" action="."
tal:attributes="action request/URL"
tal:define="contents view/getTracks">
<metal:keep-batch use-macro="content_macros/keep_batch_params" />
<div class="page_error"
tal:condition="view/error"
tal:content="view/error"
i18n:translate="">
Error message
</div>
<table id="sortable" class="listing" summary="Content listing"
i18n:attributes="summary">
<thead>
<tr>
<th i18n:translate="">ID</th>
<th i18n:translate="">Task</th>
<th i18n:translate="">Run</th>
<th i18n:translate="">User</th>
<th i18n:translate="">Timestamp</th>
</tr>
</thead>
<tbody>
<metal:block tal:define="batch nocall:context/@@cybertools.reporter.batch;
batch python:batch.setup(contents)">
<tal:list repeat="item batch/items">
<tr tal:define="oddrow repeat/item/odd;
url item/url;"
tal:attributes="class python:oddrow and 'even' or 'odd'" >
<td>
<a href="#"
tal:attributes="href string:${url}/@@SelectedManagementView.html"
tal:content="item/id">foo</a>
</td>
<td><a tal:omit-tag="not:item/taskUrl"
tal:attributes="href item/taskUrl"
tal:content="item/taskTitle"></a></td>
<td tal:content="item/run"></td>
<td><a tal:omit-tag="not:item/userUrl"
tal:attributes="href item/userUrl"
tal:content="item/userTitle"></a></td>
<td tal:content="item/timeStamp"></td>
</tr>
</tal:list>
<metal:nav use-macro="content_macros/batch_navigation_tr" />
</metal:block>
</tbody>
</table>
</form>
</div>
</div>
</body>
</html>