Commit 645a4ece authored by Sebastien Robin's avatar Sebastien Robin

allow to upload/download Files with unknown mime type

parent 48f86374
...@@ -86,16 +86,17 @@ class DownloadableMixin: ...@@ -86,16 +86,17 @@ class DownloadableMixin:
output_format = None output_format = None
if not format: if not format:
# Guess the format from original mimetype # Guess the format from original mimetype
mimetypes_registry = getToolByName(self.getPortalObject(), if mime:
'mimetypes_registry') mimetypes_registry = getToolByName(self.getPortalObject(),
mimetype_object_list = mimetypes_registry.lookup(mime) 'mimetypes_registry')
for mimetype_object in mimetype_object_list: mimetype_object_list = mimetypes_registry.lookup(mime)
if mimetype_object.extensions: for mimetype_object in mimetype_object_list:
output_format = mimetype_object.extensions[0] if mimetype_object.extensions:
break output_format = mimetype_object.extensions[0]
elif mimetype_object.globs: break
output_format = mimetype_object.globs.strip('*.') elif mimetype_object.globs:
break output_format = mimetype_object.globs.strip('*.')
break
else: else:
output_format = format output_format = format
......
...@@ -2616,6 +2616,19 @@ return 1 ...@@ -2616,6 +2616,19 @@ return 1
self.assertEqual('archived', document_nolang_005.getValidationState()) self.assertEqual('archived', document_nolang_005.getValidationState())
self.assertEqual('shared_alive', document_nolang_006.getValidationState()) self.assertEqual('shared_alive', document_nolang_006.getValidationState())
def testFileWithNotDefinedMimeType(self):
upload_file = makeFileUpload('TEST-001-en.dummy')
kw = dict(file=upload_file, synchronous_metadata_discovery=True,
portal_type='File')
document = self.portal.Base_contribute(**kw)
document.setReference('TEST')
request = self.app.REQUEST
download_file = document.index_html(REQUEST=request, format=None)
self.assertEquals(download_file, 'foo\n')
document_format = None
self.assertEquals('TEST-001-en.dummy', document.getStandardFilename(
document_format))
class TestDocumentWithSecurity(TestDocumentMixin): class TestDocumentWithSecurity(TestDocumentMixin):
username = 'yusei' username = 'yusei'
......
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