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:
parent
1327746bcb
commit
b3ecfd24e6
2 changed files with 16 additions and 1 deletions
|
@ -217,7 +217,7 @@ class BaseView(GenericView, I18NView):
|
|||
self.skin = skin
|
||||
|
||||
@Lazy
|
||||
def modified(self):
|
||||
def modifiedRaw(self):
|
||||
""" get date/time of last modification
|
||||
"""
|
||||
d = getattr(self.adapted, 'modified', None)
|
||||
|
@ -226,6 +226,11 @@ class BaseView(GenericView, I18NView):
|
|||
d = dc.modified or dc.created
|
||||
if isinstance(d, str):
|
||||
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 ''
|
||||
|
||||
@Lazy
|
||||
|
|
|
@ -176,6 +176,9 @@ class ResourceView(BaseView):
|
|||
|
||||
def show(self, useAttachment=False):
|
||||
""" show means: "download"..."""
|
||||
# TODO: control access, e.g. to protected images
|
||||
# if self.adapted.isProtected():
|
||||
# raise Unauthorized()
|
||||
context = self.context
|
||||
self.recordAccess('show', target=self.uniqueId)
|
||||
ti = IType(context).typeInterface
|
||||
|
@ -194,6 +197,13 @@ class ResourceView(BaseView):
|
|||
response.setHeader('Content-Type', 'text/html')
|
||||
return self.renderText(data, 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
|
||||
|
||||
def renderText(self, text, contentType):
|
||||
|
|
Loading…
Add table
Reference in a new issue