Translate content disposition "filename" attribute when downloading file
authorThierry Florac <thierry.florac@onf.fr>
Mon, 18 Feb 2019 09:51:24 +0100
changeset 198 e17580995a0d
parent 197 ad9ed1e729e0
child 199 d19c4bb4d374
Translate content disposition "filename" attribute when downloading file
src/pyams_file/views/file.py
--- a/src/pyams_file/views/file.py	Thu Feb 14 17:37:44 2019 +0100
+++ b/src/pyams_file/views/file.py	Mon Feb 18 09:51:24 2019 +0100
@@ -12,17 +12,14 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
 from http.client import NOT_MODIFIED, PARTIAL_CONTENT
 
-# import interfaces
-from pyams_file.interfaces import IFile
+from pyramid.response import Response
+from pyramid.view import view_config
 from zope.dublincore.interfaces import IZopeDublinCore
 
-# import packages
-from pyramid.response import Response
-from pyramid.view import view_config
+from pyams_file.interfaces import IFile
+from pyams_utils.unicode import translate_string
 
 
 MAX_RANGE_LENGTH = 1 << 21  # 2 Mb
@@ -50,7 +47,8 @@
     body_file = context.get_blob(mode='c')
 
     if request.params.get('download') is not None:
-        response.content_disposition = 'attachment; filename="{0}"'.format(context.filename)
+        response.content_disposition = 'attachment; filename="{0}"'.format(translate_string(context.filename,
+                                                                                            force_lower=False))
 
     # check for range request
     if request.range is not None: