diff --git a/product/ERP5/Document/File.py b/product/ERP5/Document/File.py index 496b34105e58dc03a1a98107a7babcec043a2d63..449d37b892cbc05b2f92762d27bdb4124a99e4ed 100644 --- a/product/ERP5/Document/File.py +++ b/product/ERP5/Document/File.py @@ -31,6 +31,7 @@ from AccessControl import ClassSecurityInfo from Products.ERP5Type.Base import WorkflowMethod from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5.Document.Document import Document, VALID_TEXT_FORMAT_LIST +from Products.ERP5.Document.Document import VALID_IMAGE_FORMAT_LIST from Products.ERP5.Document.Document import ConversionError from Products.ERP5Type.Base import Base, removeIContentishInterface from Products.CMFDefault.File import File as CMFFile @@ -241,16 +242,27 @@ class File(Document, CMFFile): return (mime_type, content) def _convert(self, format, **kw): - """File is not convertable. - Only original format and text formats are allowed. + """File is only convertable if it is an image. + Only Image conversion, original format and text formats are allowed. However this document can migrate to another portal_type which support - conversions. + others conversions. """ content_type = self.getContentType() or '' - if format is None: + if (format in VALID_IMAGE_FORMAT_LIST + (None, "")) and \ + content_type.startswith("image/"): + # The file should behave like it is an Image for convert + # the content to target format. + from Products.ERP5Type.Document import newTempImage + return newTempImage(self, self.getId(), + data=self.getData(), + content_type=content_type, + filename=self.getFilename())._convert(format, **kw) + + elif format in (None, ""): # No conversion is asked, # we can return safely the file content itself return content_type, self.getData() + elif format in VALID_TEXT_FORMAT_LIST: # This is acceptable to return empty string # for a File we can not convert diff --git a/product/ERP5/tests/testERP5WebWithDms.py b/product/ERP5/tests/testERP5WebWithDms.py index 2ac00d569a270720d721d5e50a9017c53a62e535..251c26b45383b25a6df65509b5c64539e80a0703 100644 --- a/product/ERP5/tests/testERP5WebWithDms.py +++ b/product/ERP5/tests/testERP5WebWithDms.py @@ -686,7 +686,13 @@ return True self.assertEquals(1, len(img_list)) src = img_list[0].get('src') - def test_ImageConversionThroughWebSite(self): + def test_ImageConversionThroughWebSite_using_file(self): + """Check that conversion parameters pass in url + are hounoured to display an image in context of a website + """ + self.test_ImageConversionThroughWebSite("File") + + def test_ImageConversionThroughWebSite(self, image_portal_type="Image"): """Check that conversion parameters pass in url are hounoured to display an image in context of a website """ @@ -707,9 +713,9 @@ return True image_reference = 'NXD-IMAGE' - image_module = portal.getDefaultModule(portal_type='Image') + module = portal.getDefaultModule(portal_type=image_portal_type) upload_file = makeFileUpload('tiolive-ERP5.Freedom.TioLive.Logo-001-en.png') - image = image_module.newContent(portal_type='Image', + image = module.newContent(portal_type=image_portal_type, file=upload_file, reference=image_reference) image.publish()