provide Last-Modified HTTP header for file download

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@4015 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2010-09-25 08:25:27 +00:00
parent 1327746bcb
commit b3ecfd24e6
2 changed files with 16 additions and 1 deletions

View file

@ -217,7 +217,7 @@ class BaseView(GenericView, I18NView):
self.skin = skin self.skin = skin
@Lazy @Lazy
def modified(self): def modifiedRaw(self):
""" get date/time of last modification """ get date/time of last modification
""" """
d = getattr(self.adapted, 'modified', None) d = getattr(self.adapted, 'modified', None)
@ -226,6 +226,11 @@ class BaseView(GenericView, I18NView):
d = dc.modified or dc.created d = dc.modified or dc.created
if isinstance(d, str): if isinstance(d, str):
d = datetime(*(strptime(d, '%Y-%m-%dT%H:%M')[:6])) d = datetime(*(strptime(d, '%Y-%m-%dT%H:%M')[:6]))
return d
@Lazy
def modified(self):
d = self.modifiedRaw
return d and d.strftime('%Y-%m-%d %H:%M') or '' return d and d.strftime('%Y-%m-%d %H:%M') or ''
@Lazy @Lazy

View file

@ -176,6 +176,9 @@ class ResourceView(BaseView):
def show(self, useAttachment=False): def show(self, useAttachment=False):
""" show means: "download"...""" """ show means: "download"..."""
# TODO: control access, e.g. to protected images
# if self.adapted.isProtected():
# raise Unauthorized()
context = self.context context = self.context
self.recordAccess('show', target=self.uniqueId) self.recordAccess('show', target=self.uniqueId)
ti = IType(context).typeInterface ti = IType(context).typeInterface
@ -194,6 +197,13 @@ class ResourceView(BaseView):
response.setHeader('Content-Type', 'text/html') response.setHeader('Content-Type', 'text/html')
return self.renderText(data, ct) return self.renderText(data, ct)
response.setHeader('Content-Type', ct) response.setHeader('Content-Type', ct)
# set Last-Modified header
modified = self.modifiedRaw
if modified:
format = '%a, %d %b %Y %H:%M:%S %Z'
if modified.tzinfo is None:
format = format[:-3] + ' GMT'
response.setHeader('Last-Modified', modified.strftime(format))
return data return data
def renderText(self, text, contentType): def renderText(self, text, contentType):