Commit 2097b8cd authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

add inline argument in Base_download and index_html(). add a workaround for...

add inline argument in Base_download and index_html(). add a workaround for Internet Explorer's bug.
parent 8d8dd420
...@@ -55,14 +55,8 @@ response = request.RESPONSE\n ...@@ -55,14 +55,8 @@ response = request.RESPONSE\n
\n \n
from zExceptions import Unauthorized\n from zExceptions import Unauthorized\n
\n \n
format = None\n
# Always force download of document even if format is supported\n
# by browser\n
filename = context.getStandardFilename(format)\n
response.setHeader(\'Content-disposition\', \'attachment; filename="%s"\' % filename)\n
\n
try:\n try:\n
return context.index_html(request, response, format)\n return context.index_html(request, response, format=None, inline=inline)\n
except Unauthorized:\n except Unauthorized:\n
msg = context.Base_translateString("You do not have enough permission for converting this document.")\n msg = context.Base_translateString("You do not have enough permission for converting this document.")\n
return context.Base_redirect(keep_items=dict(portal_status_message=msg))\n return context.Base_redirect(keep_items=dict(portal_status_message=msg))\n
...@@ -70,7 +64,7 @@ except Unauthorized:\n ...@@ -70,7 +64,7 @@ except Unauthorized:\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string>inline=False</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -42,7 +42,7 @@ class DownloadableMixin: ...@@ -42,7 +42,7 @@ class DownloadableMixin:
### Content processing methods ### Content processing methods
security.declareProtected(Permissions.View, 'index_html') security.declareProtected(Permissions.View, 'index_html')
@fill_args_from_request('display', 'quality', 'resolution', 'frame', 'pre_converted_only') @fill_args_from_request('display', 'quality', 'resolution', 'frame', 'pre_converted_only')
def index_html(self, REQUEST, RESPONSE, format=_MARKER, **kw): def index_html(self, REQUEST, RESPONSE, format=_MARKER, inline=_MARKER, **kw):
""" """
We follow here the standard Zope API for files and images We follow here the standard Zope API for files and images
and extend it to support format conversion. The idea and extend it to support format conversion. The idea
...@@ -104,6 +104,16 @@ class DownloadableMixin: ...@@ -104,6 +104,16 @@ class DownloadableMixin:
RESPONSE.setHeader('Content-Type', '%s; charset=utf-8' % mime) RESPONSE.setHeader('Content-Type', '%s; charset=utf-8' % mime)
else: else:
RESPONSE.setHeader('Content-Type', mime) RESPONSE.setHeader('Content-Type', mime)
if inline is _MARKER:
# by default, use inline for text and image formats
inline = output_format in (VALID_TEXT_FORMAT_LIST + VALID_IMAGE_FORMAT_LIST)
if not inline:
# need to return it as attachment
filename = self.getStandardFilename(format=format)
RESPONSE.setHeader('Cache-Control', 'Private') # workaround for Internet Explorer's bug
RESPONSE.setHeader('Content-Disposition',
'attachment; filename="%s"' % filename)
RESPONSE.setHeader('Accept-Ranges', 'bytes')
return str(data) return str(data)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment