download files via view object instead of directly linking to BSCW URL
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3227 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
bd66ed2ff4
commit
da22fa15cf
2 changed files with 36 additions and 14 deletions
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
|
# Copyright (c) 2009 Helmut Merz helmutm@cy55.de
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -24,6 +24,7 @@ $Id$
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from time import strptime
|
from time import strptime
|
||||||
|
from urllib import quote, quote_plus
|
||||||
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
|
||||||
|
@ -77,17 +78,21 @@ class ItemView(BaseView):
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def url(self):
|
def url(self):
|
||||||
if isinstance(self.context, File):
|
#if isinstance(self.context, File):
|
||||||
return self.downloadUrl
|
# return self.bscwDownloadUrl
|
||||||
url = self.parentView.url
|
url = self.parentView.url
|
||||||
return '%s?id=%s' % (url, self.context.internalPath)
|
return '%s?id=%s' % (url, self.context.internalPath)
|
||||||
|
|
||||||
@Lazy
|
def download(self):
|
||||||
def downloadUrl(self):
|
fn = self.getFileName()
|
||||||
urlInfo = self.context.externalURLInfo
|
data = self.context.getData()
|
||||||
baseUrl = urlInfo.baseUrl
|
response = self.request.response
|
||||||
while 'bscw.cgi' in baseUrl and not baseUrl.endswith('bscw.cgi'):
|
response.setHeader('Content-Type', self.context.contentType)
|
||||||
baseUrl, ignore = baseUrl.rsplit('/', 1)
|
response.setHeader('Content-Length', len(data))
|
||||||
|
response.setHeader('Content-Disposition', 'filename="%s"' % fn)
|
||||||
|
return data
|
||||||
|
|
||||||
|
def getFileName(self):
|
||||||
if (self.context.contentType == 'application/octet-stream' and
|
if (self.context.contentType == 'application/octet-stream' and
|
||||||
len(self.title) > 3 and self.title[-4] == '.'):
|
len(self.title) > 3 and self.title[-4] == '.'):
|
||||||
extension = ''
|
extension = ''
|
||||||
|
@ -99,8 +104,18 @@ class ItemView(BaseView):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
extension = '.' + extensions[0]
|
extension = '.' + extensions[0]
|
||||||
title = self.title.encode('UTF-8').replace('/', '|')
|
title = self.title.encode('UTF-8')
|
||||||
return '%s/d%s/%s%s' % (baseUrl, urlInfo.path, title, extension)
|
title = title.replace('/', '|')
|
||||||
|
return title + extension
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def bscwDownloadUrl(self):
|
||||||
|
urlInfo = self.context.externalURLInfo
|
||||||
|
baseUrl = urlInfo.baseUrl
|
||||||
|
while 'bscw.cgi' in baseUrl and not baseUrl.endswith('bscw.cgi'):
|
||||||
|
baseUrl, ignore = baseUrl.rsplit('/', 1)
|
||||||
|
fn = self.getFileName()
|
||||||
|
return '%s/d%s/%s' % (baseUrl, urlInfo.path, fn)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def breadCrumbs(self):
|
def breadCrumbs(self):
|
||||||
|
@ -117,6 +132,13 @@ class BSCWView(BaseView):
|
||||||
viewTemplate = view_macros
|
viewTemplate = view_macros
|
||||||
itemView = ItemView
|
itemView = ItemView
|
||||||
|
|
||||||
|
def __call__(self):
|
||||||
|
if isinstance(self.remoteProxy, File):
|
||||||
|
view = self.itemView(self.remoteProxy, self.request, self)
|
||||||
|
return view.download()
|
||||||
|
else:
|
||||||
|
return self.index()
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def dataMacro(self):
|
def dataMacro(self):
|
||||||
return self.viewTemplate.macros['data']
|
return self.viewTemplate.macros['data']
|
||||||
|
|
|
@ -234,13 +234,13 @@ class File(BSCWProxyBase, File):
|
||||||
|
|
||||||
def getData(self, num=None):
|
def getData(self, num=None):
|
||||||
try:
|
try:
|
||||||
data = self.server.get_document()
|
data = self.connection.server.get_document(self.address).data
|
||||||
except Fault, excp:
|
except Fault, excp:
|
||||||
logging.getLogger('cybertools.integrator.bscw').warn(str(excp))
|
logging.getLogger('cybertools.integrator.bscw').warn(str(excp))
|
||||||
item = None
|
data = ''
|
||||||
except Exception, excp:
|
except Exception, excp:
|
||||||
logging.getLogger('cybertools.integrator.bscw').error(str(excp))
|
logging.getLogger('cybertools.integrator.bscw').error(str(excp))
|
||||||
item = None
|
data = ''
|
||||||
return data
|
return data
|
||||||
data = property(getData)
|
data = property(getData)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue