Commit 9da58eb7 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

no need to call hasConversion() before getConversion() because it does mostly...

no need to call hasConversion() before getConversion() because it does mostly the same thing and waste of time. use try ... except KeyError instead.
_makeDisplayPhoto returns converted data to make it possible to use it immediately.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28369 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1adeabbb
...@@ -204,16 +204,15 @@ class Image(File, OFSImage): ...@@ -204,16 +204,15 @@ class Image(File, OFSImage):
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:
if not self.hasConversion(display=display, format=format, try:
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 # Generate photo on-the-fly
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)
mime, image = self.getConversion(display=display, format=format,
quality=quality, resolution=resolution,
frame=frame, image_size=image_size)
width, height = (image.width, image.height) width, height = (image.width, image.height)
# Set cookie for chosen size # Set cookie for chosen size
if cookie: if cookie:
...@@ -336,24 +335,24 @@ class Image(File, OFSImage): ...@@ -336,24 +335,24 @@ class Image(File, OFSImage):
Implementation of conversion for PDF files Implementation of conversion for PDF files
""" """
if format in ('text', 'txt', 'html', 'base_html', 'stripped-html'): if format in ('text', 'txt', 'html', 'base_html', 'stripped-html'):
if not self.hasConversion(format=format): try:
return self.getConversion(format=format)
except KeyError:
mime_type, data = self._convertToText(format) mime_type, data = self._convertToText(format)
self.setConversion(data, mime=mime_type, format=format) self.setConversion(data, mime=mime_type, format=format)
return self.getConversion(format=format) return (mime_type, aq_base(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:
if not self.hasConversion(display=display, format=format, try:
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 # Generate photo on-the-fly
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)
# Return resized image
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()
...@@ -382,17 +381,15 @@ class Image(File, OFSImage): ...@@ -382,17 +381,15 @@ class Image(File, OFSImage):
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:
if not self.hasConversion(display=display, format=format, try:
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 # Generate photo on-the-fly
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)
# Return resized image
mime, image = self.getConversion(display=display, format=format,
quality=quality ,resolution=resolution,
frame=frame, image_size=image_size)
RESPONSE.setHeader('Content-Type', mime) RESPONSE.setHeader('Content-Type', mime)
return image.index_html(REQUEST, RESPONSE) return image.index_html(REQUEST, RESPONSE)
...@@ -483,8 +480,6 @@ class Image(File, OFSImage): ...@@ -483,8 +480,6 @@ class Image(File, OFSImage):
def _makeDisplayPhoto(self, display, format='', quality=75, resolution=None, frame=None, def _makeDisplayPhoto(self, display, format='', quality=75, resolution=None, frame=None,
image_size=None): image_size=None):
"""Create given display.""" """Create given display."""
if not self.hasConversion(display=display, format=format, quality=quality,
resolution=resolution, frame=frame, image_size=image_size):
image = self._getDisplayPhoto(display, format=format, quality=quality, image = self._getDisplayPhoto(display, format=format, quality=quality,
resolution=resolution, frame=frame, resolution=resolution, frame=frame,
image_size=image_size) image_size=image_size)
...@@ -492,6 +487,7 @@ class Image(File, OFSImage): ...@@ -492,6 +487,7 @@ class Image(File, OFSImage):
display=display, format=format, display=display, format=format,
quality=quality, resolution=resolution, quality=quality, resolution=resolution,
frame=frame, image_size=image_size) frame=frame, image_size=image_size)
return (image.content_type, aq_base(image))
def _getAspectRatioSize(self, width, height): def _getAspectRatioSize(self, width, height):
"""Return proportional dimensions within desired size.""" """Return proportional dimensions within desired size."""
......
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