provide breadcrumbs

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2710 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2008-06-12 19:38:52 +00:00
parent cd10a2db70
commit b6d7bfa7c9
5 changed files with 53 additions and 16 deletions

View file

@ -75,6 +75,13 @@ class ItemView(BaseView):
url = self.parentView.url url = self.parentView.url
return '%s?id=%s' % (url, self.context.internalPath) return '%s?id=%s' % (url, self.context.internalPath)
@property
def breadCrumbs(self):
for p in reversed(list(self.context.parents)):
view = ItemView(p, self.request, self.parentView)
yield dict(url=view.url, title=view.title)
yield dict(url=self.url, title=self.title)
class BSCWView(BaseView): class BSCWView(BaseView):
@ -112,3 +119,4 @@ 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

@ -42,7 +42,7 @@ from cybertools.integrator.interfaces import IItemFactory, IFileFactory
baseAttributes = ['__class__', 'name', 'id', 'descr', 'notes', baseAttributes = ['__class__', 'name', 'id', 'descr', 'notes',
'bound_sub_artifacts', 'creator', 'owner', 'owners', 'bound_sub_artifacts', 'creator', 'owner', 'owners',
'ctime', 'mtime', 'atime', 'lastEvent', 'createEvent', 'ctime', 'mtime', 'atime', 'lastEvent', 'createEvent',
'lastChange', 'lastMove', 'containers', 'access'] 'lastChange', 'lastMove', 'location', 'containers', 'access']
minimalAttributes = ['__class__', 'name', 'id', 'descr', 'mtime'] minimalAttributes = ['__class__', 'name', 'id', 'descr', 'mtime']
@ -54,8 +54,9 @@ 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', standardAttributes = ['__class__', 'type', 'id', 'name', 'descr',
'ctime', 'mtime', 'creator', 'owner', 'owner', 'ctime', 'mtime', 'creator', 'owner', 'owners',
'url_link', 'size', 'encoding'] 'url_link', 'size', 'encoding',
'containers', 'location']
classes = ['cl_core.Folder', 'cl_core.Document', 'cl_core.URL', ] classes = ['cl_core.Folder', 'cl_core.Document', 'cl_core.URL', ]
@ -81,14 +82,14 @@ class BSCWConnection(object):
if url: if url:
self.baseURL, self.rootId = url.rsplit('/', 1) self.baseURL, self.rootId = url.rsplit('/', 1)
def getItem(self, address): def getItem(self, address, nested=True):
return self.server.get_attributes(address, standardAttributes, 1, True) return self.server.get_attributes(address, standardAttributes, 1, nested)
def getProxy(self, item=None, address=None, parentPath=''): def getProxy(self, item=None, address=None, parentPath='', nested=True):
if item is None: if item is None:
if address is None: if address is None:
address = self.rootId address = self.rootId
item = self.getItem(address)[0] item = self.getItem(address, nested=nested)[0]
address = item['id'] address = item['id']
itemType = item['__class__'].split('.')[-1] itemType = item['__class__'].split('.')[-1]
internalPath = '/'.join((parentPath, address)).strip('/') internalPath = '/'.join((parentPath, address)).strip('/')
@ -122,9 +123,7 @@ class BSCWProxyBase(object):
@Lazy @Lazy
def externalURLInfo(self): def externalURLInfo(self):
id = self.address id = self.address.lstrip('bs_')
if id.startswith('bs_'):
id = id[3:]
return ExternalURLInfo(self.baseURL, id) return ExternalURLInfo(self.baseURL, id)
@Lazy @Lazy
@ -148,6 +147,18 @@ class BSCWProxyBase(object):
dt = self.properties['mtime'] dt = self.properties['mtime']
return dt and datetime(*(strptime(str(dt), '%Y%m%dT%H:%M:%SZ')[0:6])) or '' return dt and datetime(*(strptime(str(dt), '%Y%m%dT%H:%M:%SZ')[0:6])) or ''
@property
def parents(self):
if self.address.lstrip('bs_') == self.connection.rootId:
return
parentId = self.properties['location']['__id__'].lstrip('bs_')
p = self.connection.getProxy(address=parentId, nested=False)
while parentId != self.connection.rootId:
yield p
parentId = p.properties['location']['__id__'].lstrip('bs_')
p = self.connection.getProxy(address=parentId)
yield p
class ReadContainer(BSCWProxyBase, ReadContainer): class ReadContainer(BSCWProxyBase, ReadContainer):

View file

@ -62,6 +62,9 @@ We can now access the root object of the BSCW repository.
>>> str(root.externalURLInfo) >>> str(root.externalURLInfo)
'http://localhost/bscw.cgi/4' 'http://localhost/bscw.cgi/4'
>>> list(root.parents)
[]
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.
>>> bs_5 = root['bs_5'] >>> bs_5 = root['bs_5']
@ -82,6 +85,16 @@ Let's also have a look at the item contained in the root object.
>>> str(bs_5.externalURLInfo) >>> str(bs_5.externalURLInfo)
'http://localhost/bscw.cgi/5' 'http://localhost/bscw.cgi/5'
>>> bs_5.properties['containers']
[{'name': 'public', '__id__': 'bs_4'}]
>>> [p.address for p in bs_5.parents]
['bs_4']
>>> bs_6 = bs_5['bs_6']
>>> [p.address for p in bs_6.parents]
['bs_5', 'bs_4']
The BSCW Repository View The BSCW Repository View
======================== ========================
@ -104,6 +117,10 @@ The BSCW Repository View
>>> items[0].icon >>> items[0].icon
'http://127.0.0.1/++resource++folder.png' 'http://127.0.0.1/++resource++folder.png'
>>> list(items[0].breadCrumbs)
[{'url': 'http://127.0.0.1/bscw?id=bs_4', 'title': 'public'},
{'url': 'http://127.0.0.1/bscw?id=bs_5', 'title': 'Introduction'}]
Fin de partie Fin de partie
============= =============

View file

@ -32,7 +32,6 @@ from zope.interface import implements, Attribute
from cybertools.integrator.base import ContainerFactory, FileFactory from cybertools.integrator.base import ContainerFactory, FileFactory
from cybertools.integrator.base import ReadContainer, File, Image from cybertools.integrator.base import ReadContainer, File, Image
from cybertools.text import mimetypes
# proxy classes # proxy classes

View file

@ -51,25 +51,27 @@ class BSCWRepository(dict):
for obj in objs: for obj in objs:
self[obj.id] = obj self[obj.id] = obj
obj.repository = self obj.repository = self
self.updateContainersAttribute() self.updateLocation()
def get(self, key, default=None): def get(self, key, default=None):
if not key.startswith('bs_'): if not key.startswith('bs_'):
key = 'bs_' + key key = 'bs_' + key
return super(BSCWRepository, self).get(key, default) return super(BSCWRepository, self).get(key, default)
def updateContainersAttribute(self): def updateLocation(self):
for obj in self.values(): for obj in self.values():
for c in obj.children: for c in obj.children:
child = self.get(c) child = self.get(c)
if child is not None: if child is not None:
containerInfo = dict(__id__=child.id, name=child['name']) containerInfo = dict(__id__=obj.id, name=obj['name'])
child.setdefault('containers', []).append(containerInfo) child['containers'] = [containerInfo]
child['location'] = containerInfo
sampleObjects = BSCWRepository( sampleObjects = BSCWRepository(
Artifact('4', name='public', descr='Public Repository', children=['5'], Artifact('4', name='public', descr='Public Repository', children=['5'],
containers=[dict(__id__='4711', name='Community of Anonymous')]), containers=[dict(__id__='4711', name='Community of Anonymous')],
location=dict(__id__='4711', name='Community of Anonymous')),
Artifact('5', name='Introduction', descr='Introduction to BSCW', Artifact('5', name='Introduction', descr='Introduction to BSCW',
children=['6', '7']), children=['6', '7']),
Artifact('6', name='Overview', descr='BSCW Overview', Artifact('6', name='Overview', descr='BSCW Overview',