Commit 836f816f authored by Nicolas Delaby's avatar Nicolas Delaby

Use Conversion API. hasConversion, getConversion, ...

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28985 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a1ed2243
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
...@@ -310,6 +311,7 @@ class Image(File, OFSImage): ...@@ -310,6 +311,7 @@ class Image(File, OFSImage):
""" """
mime_type = getToolByName(self, 'mimetypes_registry').\ mime_type = getToolByName(self, 'mimetypes_registry').\
lookupExtension('name.%s' % format) lookupExtension('name.%s' % format)
mime_type = str(mime_type)
src_mimetype = self.getContentType() src_mimetype = self.getContentType()
content = '%s' % self.getData() content = '%s' % self.getData()
if content is not None: if content is not None:
...@@ -332,27 +334,32 @@ class Image(File, OFSImage): ...@@ -332,27 +334,32 @@ class Image(File, OFSImage):
security.declareProtected(Permissions.ModifyPortalContent, 'convert') security.declareProtected(Permissions.ModifyPortalContent, 'convert')
def convert(self, format, display=None, quality=75, resolution=None, frame=None, **kw): def convert(self, format, display=None, quality=75, resolution=None, frame=None, **kw):
""" """
Implementation of conversion for PDF files Implementation of conversion for Image files
""" """
if format in ('text', 'txt', 'html', 'base_html', 'stripped-html'): if format in ('text', 'txt', 'html', 'base_html', 'stripped-html'):
try: if not self.hasConversion(format=format):
return self.getConversion(format=format)
except KeyError:
mime_type, data = self._convertToText(format) mime_type, data = self._convertToText(format)
data = aq_base(data)
self.setConversion(data, mime=mime_type, format=format) self.setConversion(data, mime=mime_type, format=format)
return (mime_type, aq_base(data)) else:
mime_type, data = self.getConversion(format=format)
return mime_type, data
image_size = self.getSizeFromImageDisplay(display) image_size = self.getSizeFromImageDisplay(display)
if (display is not None or resolution is not None or quality != 75 or format != ''\ if (display is not None or resolution is not None or quality != 75 or format != ''\
or frame is not None) and image_size: or frame is not None) and image_size:
try: if not self.hasConversion(display=display, format=format,
mime, image = self.getConversion(display=display, format=format, quality=quality, resolution=resolution,
quality=quality, resolution=resolution, frame=frame, image_size=image_size):
frame=frame, image_size=image_size)
except KeyError:
# Generate photo on-the-fly
mime, image = self._makeDisplayPhoto(display, format=format, quality=quality, mime, image = self._makeDisplayPhoto(display, format=format, quality=quality,
resolution=resolution, frame=frame, resolution=resolution, frame=frame,
image_size=image_size) image_size=image_size)
self.setConversion(image, mime, format=format, quality=quality,
resolution=resolution, frame=frame,
image_size=image_size)
else:
mime, image = self.getConversion(display=display, format=format,
quality=quality, resolution=resolution,
frame=frame, image_size=image_size)
return mime, image.data return mime, image.data
return self.getContentType(), self.getData() return self.getContentType(), self.getData()
......
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