diff --git a/browser/common.py b/browser/common.py index fd98c66..dcc964d 100644 --- a/browser/common.py +++ b/browser/common.py @@ -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 diff --git a/browser/resource.py b/browser/resource.py index c5d6afa..ba3f53c 100644 --- a/browser/resource.py +++ b/browser/resource.py @@ -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):