diff --git a/integrator/browser/bscw.py b/integrator/browser/bscw.py index 1eaef41..4cd68bc 100644 --- a/integrator/browser/bscw.py +++ b/integrator/browser/bscw.py @@ -75,6 +75,13 @@ class ItemView(BaseView): url = self.parentView.url 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): @@ -112,3 +119,4 @@ class BSCWView(BaseView): proxy = self.remoteProxy for obj in proxy.values(): yield self.itemView(obj, self.request, self) + diff --git a/integrator/bscw.py b/integrator/bscw.py index bc60a1e..3a8fd82 100644 --- a/integrator/bscw.py +++ b/integrator/bscw.py @@ -42,7 +42,7 @@ from cybertools.integrator.interfaces import IItemFactory, IFileFactory baseAttributes = ['__class__', 'name', 'id', 'descr', 'notes', 'bound_sub_artifacts', 'creator', 'owner', 'owners', 'ctime', 'mtime', 'atime', 'lastEvent', 'createEvent', - 'lastChange', 'lastMove', 'containers', 'access'] + 'lastChange', 'lastMove', 'location', 'containers', 'access'] 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'] standardAttributes = ['__class__', 'type', 'id', 'name', 'descr', - 'ctime', 'mtime', 'creator', 'owner', 'owner', - 'url_link', 'size', 'encoding'] + 'ctime', 'mtime', 'creator', 'owner', 'owners', + 'url_link', 'size', 'encoding', + 'containers', 'location'] classes = ['cl_core.Folder', 'cl_core.Document', 'cl_core.URL', ] @@ -81,14 +82,14 @@ class BSCWConnection(object): if url: self.baseURL, self.rootId = url.rsplit('/', 1) - def getItem(self, address): - return self.server.get_attributes(address, standardAttributes, 1, True) + def getItem(self, address, nested=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 address is None: address = self.rootId - item = self.getItem(address)[0] + item = self.getItem(address, nested=nested)[0] address = item['id'] itemType = item['__class__'].split('.')[-1] internalPath = '/'.join((parentPath, address)).strip('/') @@ -122,9 +123,7 @@ class BSCWProxyBase(object): @Lazy def externalURLInfo(self): - id = self.address - if id.startswith('bs_'): - id = id[3:] + id = self.address.lstrip('bs_') return ExternalURLInfo(self.baseURL, id) @Lazy @@ -148,6 +147,18 @@ class BSCWProxyBase(object): dt = self.properties['mtime'] 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): diff --git a/integrator/bscw.txt b/integrator/bscw.txt index 7c023f8..36c4de7 100644 --- a/integrator/bscw.txt +++ b/integrator/bscw.txt @@ -62,6 +62,9 @@ We can now access the root object of the BSCW repository. >>> str(root.externalURLInfo) 'http://localhost/bscw.cgi/4' + >>> list(root.parents) + [] + Let's also have a look at the item contained in the root object. >>> 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) '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 ======================== @@ -104,6 +117,10 @@ The BSCW Repository View >>> items[0].icon '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 ============= diff --git a/integrator/filesystem.py b/integrator/filesystem.py index 6507074..e1dee2c 100644 --- a/integrator/filesystem.py +++ b/integrator/filesystem.py @@ -32,7 +32,6 @@ from zope.interface import implements, Attribute from cybertools.integrator.base import ContainerFactory, FileFactory from cybertools.integrator.base import ReadContainer, File, Image -from cybertools.text import mimetypes # proxy classes diff --git a/integrator/tests/bscw.py b/integrator/tests/bscw.py index b152023..6d30ffb 100644 --- a/integrator/tests/bscw.py +++ b/integrator/tests/bscw.py @@ -51,25 +51,27 @@ class BSCWRepository(dict): for obj in objs: self[obj.id] = obj obj.repository = self - self.updateContainersAttribute() + self.updateLocation() def get(self, key, default=None): if not key.startswith('bs_'): key = 'bs_' + key return super(BSCWRepository, self).get(key, default) - def updateContainersAttribute(self): + def updateLocation(self): for obj in self.values(): for c in obj.children: child = self.get(c) if child is not None: - containerInfo = dict(__id__=child.id, name=child['name']) - child.setdefault('containers', []).append(containerInfo) + containerInfo = dict(__id__=obj.id, name=obj['name']) + child['containers'] = [containerInfo] + child['location'] = containerInfo sampleObjects = BSCWRepository( 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', children=['6', '7']), Artifact('6', name='Overview', descr='BSCW Overview',