Commit 48ee69f7 authored by Rafael Monnerat's avatar Rafael Monnerat

Added support for Image Conversion to File

If the file content is an image, use newTempImage to add conversion support
to the file.
parent d48c53bc
......@@ -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
......
......@@ -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()
......
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