--- a/src/pyams_file/views/file.py Tue Sep 08 17:15:57 2015 +0200
+++ b/src/pyams_file/views/file.py Tue Sep 08 17:16:34 2015 +0200
@@ -17,7 +17,7 @@
from http.client import NOT_MODIFIED
# import interfaces
-from pyams_file.interfaces import IFile, IImage
+from pyams_file.interfaces import IFile, IMediaFile
from zope.dublincore.interfaces import IZopeDublinCore
# import packages
@@ -34,28 +34,31 @@
modified = IZopeDublinCore(context).modified
if_modified_since = request.if_modified_since
if if_modified_since and (int(modified.timestamp()) <= int(if_modified_since.timestamp())):
- return Response(status=NOT_MODIFIED)
+ return Response(content_type=context.content_type.decode('utf-8'),
+ status=NOT_MODIFIED)
- headers = {'Content-Disposition': 'attachment; filename="{0}"'.format(context.filename)}
response = Response(content_type=context.content_type.decode('utf-8'),
- headers=headers)
- response.last_modified = modified
+ content_disposition='attachment; filename="{0}"'.format(context.filename),
+ last_modified=modified)
response.body_file = context.get_blob(mode='c')
return response
-@view_config(context=IImage)
-def ImageView(request):
- """Default image view"""
+@view_config(context=IMediaFile)
+def MediaFileView(request):
+ """Default media file view"""
context = request.context
# check for last modification date
modified = IZopeDublinCore(context).modified
if_modified_since = request.if_modified_since
if if_modified_since and (int(modified.timestamp()) <= int(if_modified_since.timestamp())):
- return Response(status=NOT_MODIFIED)
+ return Response(content_type=context.content_type.decode('utf-8'),
+ status=NOT_MODIFIED)
- response = Response(content_type=context.content_type.decode('utf-8'))
- response.last_modified = modified
+ response = Response(content_type=context.content_type.decode('utf-8'),
+ last_modified=modified)
+ if request.params.get('download') is not None:
+ response.content_disposition = 'attachment; filename="{0}"'.format(context.filename)
response.body_file = context.get_blob(mode='c')
return response