make access fault-tolerant - show error message; show top-level link on breadcrumbs again

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2796 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2008-08-10 09:04:21 +00:00
parent 95a372807e
commit ea156942ec
2 changed files with 33 additions and 7 deletions

View file

@ -78,11 +78,12 @@ class ItemView(BaseView):
@property @property
def breadCrumbs(self): def breadCrumbs(self):
parents = list(self.context.parents) parents = list(self.context.parents)
for p in reversed(parents[:-1]): #for p in reversed(parents[:-1]):
for p in reversed(parents):
view = ItemView(p, self.request, self.parentView) view = ItemView(p, self.request, self.parentView)
yield dict(url=view.url, title=view.title) yield dict(url=view.url, title=view.title)
#if parents: if parents:
# yield dict(url=self.url, title=self.title) yield dict(url=self.url, title=self.title)
class BSCWView(BaseView): class BSCWView(BaseView):
@ -100,6 +101,8 @@ class BSCWView(BaseView):
@Lazy @Lazy
def itemMacro(self): def itemMacro(self):
if self.remoteProxy is None:
return None
typeName = self.remoteProxy.itemType.lower() typeName = self.remoteProxy.itemType.lower()
return self.viewTemplate.macros.get(typeName, self.defaultMacro) return self.viewTemplate.macros.get(typeName, self.defaultMacro)
@ -115,6 +118,8 @@ class BSCWView(BaseView):
@Lazy @Lazy
def item(self): def item(self):
if self.remoteProxy is None:
return None
return self.itemView(self.remoteProxy, self.request, self) return self.itemView(self.remoteProxy, self.request, self)
def content(self): def content(self):

View file

@ -22,10 +22,11 @@ Access to objects in a BSCW repository.
$Id$ $Id$
""" """
import logging
import os import os
from datetime import datetime from datetime import datetime
from time import strptime from time import strptime
from xmlrpclib import ServerProxy from xmlrpclib import ServerProxy, Fault
from zope import component from zope import component
from zope.app.file.image import getImageInfo from zope.app.file.image import getImageInfo
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
@ -83,13 +84,25 @@ class BSCWConnection(object):
self.baseURL, self.rootId = url.rsplit('/', 1) self.baseURL, self.rootId = url.rsplit('/', 1)
def getItem(self, address, nested=True): def getItem(self, address, nested=True):
return self.server.get_attributes(address, standardAttributes, 1, nested) try:
item = self.server.get_attributes(address, standardAttributes, 1, nested)
except Fault, excp:
logging.getLogger('cybertools.integrator.bscw').warn(str(excp))
item = None
except Exception, excp:
logging.getLogger('cybertools.integrator.bscw').error(str(excp))
item = None
return item
def getProxy(self, item=None, address=None, parentPath='', nested=True): 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, nested=nested)[0] items = self.getItem(address, nested=nested)
if items:
item = items[0]
else:
return None
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('/')
@ -220,7 +233,15 @@ class File(BSCWProxyBase, File):
contentType = None contentType = None
def getData(self, num=None): def getData(self, num=None):
return self.server.get_document() try:
data = self.server.get_document()
except Fault, excp:
logging.getLogger('cybertools.integrator.bscw').warn(str(excp))
item = None
except Exception, excp:
logging.getLogger('cybertools.integrator.bscw').error(str(excp))
item = None
return data
data = property(getData) data = property(getData)
def getSize(self): def getSize(self):