show more informations on items

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2676 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2008-06-07 16:51:42 +00:00
parent 73311e2cf8
commit 46b2018eb3
5 changed files with 76 additions and 27 deletions

View file

@ -152,7 +152,7 @@ class Image(File):
# URL info # URL info
class ExternalUrlInfo(object): class ExternalURLInfo(object):
def __init__(self, baseUrl='', path='', params=None): def __init__(self, baseUrl='', path='', params=None):
self.baseUrl, self.path = baseUrl.strip('/'), path.strip('/') self.baseUrl, self.path = baseUrl.strip('/'), path.strip('/')

View file

@ -22,6 +22,8 @@ BSCW repository view.
$Id$ $Id$
""" """
from datetime import datetime
from time import strptime
from zope.app.pagetemplate import ViewPageTemplateFile from zope.app.pagetemplate import ViewPageTemplateFile
from zope import component from zope import component
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
@ -49,6 +51,10 @@ class BaseView(object):
def description(self): def description(self):
return self.context.description return self.context.description
@Lazy
def modified(self):
return self.context.modified
@Lazy @Lazy
def url(self): def url(self):
return absoluteURL(self.context, self.request) return absoluteURL(self.context, self.request)
@ -76,13 +82,22 @@ class BSCWView(BaseView):
itemView = ItemView itemView = ItemView
@Lazy @Lazy
def listing(self): def dataMacro(self):
return self.viewTemplate.macros['listing'] return self.viewTemplate.macros['data']
@Lazy @Lazy
def heading(self): def headingMacro(self):
return self.viewTemplate.macros['heading'] return self.viewTemplate.macros['heading']
@Lazy
def itemMacro(self):
typeName = self.remoteProxy.itemType.lower()
return self.viewTemplate.macros.get(typeName, self.defaultMacro)
@Lazy
def defaultMacro(self):
return self.viewTemplate.macros['default']
@Lazy @Lazy
def remoteProxy(self): def remoteProxy(self):
id = self.request.form.get('id') id = self.request.form.get('id')
@ -97,4 +112,3 @@ class BSCWView(BaseView):
proxy = self.remoteProxy proxy = self.remoteProxy
for obj in proxy.values(): for obj in proxy.values():
yield self.itemView(obj, self.request, self) yield self.itemView(obj, self.request, self)

View file

@ -2,39 +2,67 @@
<metal:view define-macro="heading" <metal:view define-macro="heading"
tal:define="item view/item"> tal:define="item view/item">
<p i18n:translate="box_last_modified" />
<h2> <h2>
<img tal:attributes="src item/icon" /> <img tal:attributes="src item/icon" />
<span tal:content="item/title">Title</span> <span tal:content="item/title">Title</span>
</h2> </h2>
<p class="description"
tal:content="item/description" />
<p tal:define="url view/remoteProxy/externalURLInfo">
<a tal:attributes="href url"
tal:content="url">Link</a>
</p>
</metal:view> </metal:view>
<metal:data define-macro="data"> <metal:data define-macro="data">
<metal:block use-macro="view/viewTemplate/macros/properties" />
<metal:block use-macro="view/itemMacro" />
</metal:data>
<metal:properties define-macro="properties">
<div tal:content="view/remoteProxy/properties" />
</metal:properties>
<metal:data define-macro="default">
<div tal:content="view/remoteProxy/itemType"></div>
</metal:data> </metal:data>
<metal:document define-macro="document"> <metal:document define-macro="document">
<div></div>
</metal:document> </metal:document>
<metal:url define-macro="url"> <metal:url define-macro="url">
<div tal:define="url view/remoteProxy/properties/url_link">
<a tal:attributes="href url"
tal:content="url">Link</a>
</div>
</metal:url> </metal:url>
<metal:listing define-macro="listing"> <metal:folder define-macro="folder">
<dl tal:condition="python: view.remoteProxy.itemType == 'Folder'"> <dl>
<tal:item repeat="item view/content"> <tal:item repeat="item view/content">
<dt> <dt>
<a tal:attributes="href item/url"> <a tal:attributes="href item/url">
<img width="16" height="16" <img width="16" height="16"
tal:attributes="src item/icon" /> tal:attributes="src item/icon" />
</a> </a>
<a tal:attributes="href item/url"> <a tal:attributes="href item/url"><span tal:content="item/title" /></a>
<span tal:content="item/title" /> <span class="documentByLine">
</a> &mdash;
<span i18n:translate="box_last_modified">last modified:</span>
<span tal:content="item/modified" />
</span>
</dt> </dt>
<dd tal:content="item/description"> <dd tal:content="item/description">
</dd> </dd>
</tal:item> </tal:item>
</dl> </dl>
</metal:listing> </metal:folder>

View file

@ -23,6 +23,8 @@ $Id$
""" """
import os import os
from datetime import datetime
from time import strptime
from xmlrpclib import ServerProxy from xmlrpclib import ServerProxy
from zope import component from zope import component
from zope.app.file.image import getImageInfo from zope.app.file.image import getImageInfo
@ -32,7 +34,7 @@ from zope.interface import implements, Attribute
from cybertools.integrator.base import ContainerFactory, ItemFactory, FileFactory from cybertools.integrator.base import ContainerFactory, ItemFactory, FileFactory
from cybertools.integrator.base import ReadContainer, Item, File, Image from cybertools.integrator.base import ReadContainer, Item, File, Image
from cybertools.integrator.base import ExternalUrlInfo from cybertools.integrator.base import ExternalURLInfo
from cybertools.integrator.interfaces import IContainerFactory from cybertools.integrator.interfaces import IContainerFactory
from cybertools.integrator.interfaces import IItemFactory, IFileFactory from cybertools.integrator.interfaces import IItemFactory, IFileFactory
from cybertools.text import mimetypes from cybertools.text import mimetypes
@ -43,7 +45,7 @@ baseAttributes = ['__class__', 'name', 'id', 'descr', 'notes',
'ctime', 'mtime', 'atime', 'lastEvent', 'createEvent', 'ctime', 'mtime', 'atime', 'lastEvent', 'createEvent',
'lastChange', 'lastMove', 'containers', 'access'] 'lastChange', 'lastMove', 'containers', 'access']
standardAttributes = ['__class__', 'name', 'id', 'descr', 'mtime'] minimalAttributes = ['__class__', 'name', 'id', 'descr', 'mtime']
additionalAttributes = ['banner', 'moderated', 'ratings'] additionalAttributes = ['banner', 'moderated', 'ratings']
@ -52,6 +54,10 @@ documentAttributes = ['vid', 'vstore', 'file_extensions', 'size', 'encoding', 't
urlAttributes = ['url_link', 'last_verified', 'last_error', 'content_length', urlAttributes = ['url_link', 'last_verified', 'last_error', 'content_length',
'content_type', 'content_encoding', 'last_modified'] 'content_type', 'content_encoding', 'last_modified']
standardAttributes = ['__class__', 'type', 'id', 'name', 'descr',
'ctime', 'mtime', 'creator', 'owner', 'owner',
'url_link', 'size', 'encoding']
classes = ['cl_core.Folder', 'cl_core.Document', 'cl_core.URL', ] classes = ['cl_core.Folder', 'cl_core.Document', 'cl_core.URL', ]
@ -77,8 +83,7 @@ class BSCWConnection(object):
self.baseURL, self.rootId = url.rsplit('/', 1) self.baseURL, self.rootId = url.rsplit('/', 1)
def getItem(self, address): def getItem(self, address):
return self.server.get_attributes(address, return self.server.get_attributes(address, standardAttributes, 1, True)
['__class__', 'type', 'id', 'name', 'descr', 'url_link'], 1, True)
def getProxy(self, item=None, address=None, parentPath=''): def getProxy(self, item=None, address=None, parentPath=''):
if item is None: if item is None:
@ -117,11 +122,11 @@ class BSCWConnection(object):
class BSCWProxyBase(object): class BSCWProxyBase(object):
@Lazy @Lazy
def externalUrlInfo(self): def externalURLInfo(self):
id = self.address id = self.address
if id.startswith('bs_'): if id.startswith('bs_'):
id = id[3:] id = id[3:]
return ExternalUrlInfo(self.baseURL, id) return ExternalURLInfo(self.baseURL, id)
@Lazy @Lazy
def attributes(self): def attributes(self):
@ -139,6 +144,11 @@ class BSCWProxyBase(object):
def description(self): def description(self):
return self.properties.get('descr', u'') return self.properties.get('descr', u'')
@Lazy
def modified(self):
dt = self.properties['mtime']
return dt and datetime(*(strptime(str(dt), '%Y%m%dT%H:%M:%SZ')[0:6])) or ''
class ReadContainer(BSCWProxyBase, ReadContainer): class ReadContainer(BSCWProxyBase, ReadContainer):
@ -205,20 +215,17 @@ class File(BSCWProxyBase, File):
return 0 return 0
class Image(File, Image):
pass
# factory classes # factory classes
class ContainerFactory(ContainerFactory): class ContainerFactory(ContainerFactory):
proxyClass = ReadContainer proxyClass = ReadContainer
def xxx__call__(self, address, **kw):
server = kw.pop('server')
if isinstance(server, basestring): # just a URL, resolve for XML-RPC
server = ServerProxy(server)
baseURL = server
baseURL = kw.pop('baseURL', '')
return self.proxyClass(address, server=server, baseURL=baseURL, **kw)
class ItemFactory(ItemFactory): class ItemFactory(ItemFactory):

View file

@ -59,7 +59,7 @@ We can now access the root object of the BSCW repository.
>>> root.description >>> root.description
'Public Repository' 'Public Repository'
>>> str(root.externalUrlInfo) >>> str(root.externalURLInfo)
'http://localhost/bscw.cgi/4' 'http://localhost/bscw.cgi/4'
Let's also have a look at the item contained in the root object. Let's also have a look at the item contained in the root object.
@ -79,7 +79,7 @@ Let's also have a look at the item contained in the root object.
>>> bs_5.properties >>> bs_5.properties
{...'name': 'Introduction'...} {...'name': 'Introduction'...}
>>> str(bs_5.externalUrlInfo) >>> str(bs_5.externalURLInfo)
'http://localhost/bscw.cgi/5' 'http://localhost/bscw.cgi/5'