Commit befe4a3a authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

make a valid extention for a file generated by 'Download Open Document' action.

parent d5bc2ebd
......@@ -85,7 +85,7 @@ class DownloadableMixin:
'format')
mime, data = self.convert(format, **kw)
output_format = None
if not format:
if not format or format == 'base-data':
# Guess the format from original mimetype
if mime:
mimetypes_registry = getToolByName(self.getPortalObject(),
......@@ -98,7 +98,7 @@ class DownloadableMixin:
elif mimetype_object.globs:
output_format = mimetype_object.globs.strip('*.')
break
else:
if output_format is None:
output_format = format
RESPONSE.setHeader('Content-Length', len(data))
......@@ -111,6 +111,9 @@ class DownloadableMixin:
inline = output_format in (VALID_TEXT_FORMAT_LIST + VALID_IMAGE_FORMAT_LIST)
if not inline:
# need to return it as attachment
if format == 'base-data':
filename = self.getStandardFilename(format=output_format)
else:
filename = self.getStandardFilename(format=format)
RESPONSE.setHeader('Cache-Control', 'Private') # workaround for Internet Explorer's bug
# workaround for IE's bug to download files over SSL
......
......@@ -631,12 +631,14 @@ class TestDocument(TestDocumentMixin):
self.assertTrue(doc.hasData())
def test_Owner_Base_download(self):
# tests that owners can download OOo documents, and all headers (including
# filenames) are set correctly
# tests that owners can download original documents and OOo
# documents, and all headers (including filenames) are set
# correctly
doc = self.portal.document_module.newContent(
filename='test.ods',
portal_type='Spreadsheet')
doc.edit(file=makeFileUpload('import_data_list.ods'))
doc.edit(file=makeFileUpload('TEST-en-002.doc'))
self.tic()
uf = self.portal.acl_users
uf._doAddUser('member_user1', 'secret', ['Member', 'Owner'], [])
......@@ -645,13 +647,18 @@ class TestDocument(TestDocumentMixin):
response = self.publish('%s/Base_download' % doc.getPath(),
basic='member_user1:secret')
self.assertEqual(makeFileUpload('import_data_list.ods').read(),
self.assertEqual(makeFileUpload('TEST-en-002.doc').read(),
response.getBody())
self.assertEqual('application/vnd.oasis.opendocument.spreadsheet',
self.assertEqual('application/msword',
response.headers['content-type'])
self.assertEqual('attachment; filename="import_data_list.ods"',
self.assertEqual('attachment; filename="TEST-en-002.doc"',
response.headers['content-disposition'])
response = self.publish('%s/OOoDocument_getOOoFile' % doc.getPath(),
basic='member_user1:secret')
self.assertEqual('application/vnd.oasis.opendocument.text',
response.headers['content-type'])
self.assertEqual('attachment; filename="TEST-en-002.odt"',
response.headers['content-disposition'])
self.tic()
def test_Member_download_pdf_format(self):
# tests that members can download OOo documents in pdf format (at least in
......
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