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
class ExternalUrlInfo(object):
class ExternalURLInfo(object):
def __init__(self, baseUrl='', path='', params=None):
self.baseUrl, self.path = baseUrl.strip('/'), path.strip('/')

View file

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

View file

@ -2,39 +2,67 @@
<metal:view define-macro="heading"
tal:define="item view/item">
<p i18n:translate="box_last_modified" />
<h2>
<img tal:attributes="src item/icon" />
<span tal:content="item/title">Title</span>
</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: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:document define-macro="document">
<div></div>
</metal:document>
<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:listing define-macro="listing">
<dl tal:condition="python: view.remoteProxy.itemType == 'Folder'">
<metal:folder define-macro="folder">
<dl>
<tal:item repeat="item view/content">
<dt>
<a tal:attributes="href item/url">
<img width="16" height="16"
tal:attributes="src item/icon" />
</a>
<a tal:attributes="href item/url">
<span tal:content="item/title" />
</a>
<a tal:attributes="href item/url"><span tal:content="item/title" /></a>
<span class="documentByLine">
&mdash;
<span i18n:translate="box_last_modified">last modified:</span>
<span tal:content="item/modified" />
</span>
</dt>
<dd tal:content="item/description">
</dd>
</tal:item>
</dl>
</metal:listing>
</metal:folder>

View file

@ -23,6 +23,8 @@ $Id$
"""
import os
from datetime import datetime
from time import strptime
from xmlrpclib import ServerProxy
from zope import component
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 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 IItemFactory, IFileFactory
from cybertools.text import mimetypes
@ -43,7 +45,7 @@ baseAttributes = ['__class__', 'name', 'id', 'descr', 'notes',
'ctime', 'mtime', 'atime', 'lastEvent', 'createEvent',
'lastChange', 'lastMove', 'containers', 'access']
standardAttributes = ['__class__', 'name', 'id', 'descr', 'mtime']
minimalAttributes = ['__class__', 'name', 'id', 'descr', 'mtime']
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',
'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', ]
@ -77,8 +83,7 @@ class BSCWConnection(object):
self.baseURL, self.rootId = url.rsplit('/', 1)
def getItem(self, address):
return self.server.get_attributes(address,
['__class__', 'type', 'id', 'name', 'descr', 'url_link'], 1, True)
return self.server.get_attributes(address, standardAttributes, 1, True)
def getProxy(self, item=None, address=None, parentPath=''):
if item is None:
@ -117,11 +122,11 @@ class BSCWConnection(object):
class BSCWProxyBase(object):
@Lazy
def externalUrlInfo(self):
def externalURLInfo(self):
id = self.address
if id.startswith('bs_'):
id = id[3:]
return ExternalUrlInfo(self.baseURL, id)
return ExternalURLInfo(self.baseURL, id)
@Lazy
def attributes(self):
@ -139,6 +144,11 @@ class BSCWProxyBase(object):
def description(self):
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):
@ -205,20 +215,17 @@ class File(BSCWProxyBase, File):
return 0
class Image(File, Image):
pass
# factory classes
class ContainerFactory(ContainerFactory):
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):

View file

@ -59,7 +59,7 @@ We can now access the root object of the BSCW repository.
>>> root.description
'Public Repository'
>>> str(root.externalUrlInfo)
>>> str(root.externalURLInfo)
'http://localhost/bscw.cgi/4'
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
{...'name': 'Introduction'...}
>>> str(bs_5.externalUrlInfo)
>>> str(bs_5.externalURLInfo)
'http://localhost/bscw.cgi/5'