Commit 84f8d28a authored by Nicolas Delaby's avatar Nicolas Delaby

Various small refactoring:

  * Call hasData instead of get_size to follow ERP5 API
  * call getSizeFromImageDisplay()only once
  * getSizeFromImageDisplay will return default dimension of
    Image itself of display is not inside DEFAULT_DISPLAY_ID_LIST


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35239 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b68549a9
...@@ -160,7 +160,8 @@ class Image(TextConvertableMixin, File, OFSImage): ...@@ -160,7 +160,8 @@ class Image(TextConvertableMixin, File, OFSImage):
Tries to get the width from the image data. Tries to get the width from the image data.
""" """
self._upradeImage() self._upradeImage()
if self.get_size() and not self.width: self._update_image_info() if self.hasData() and not self.width:
self._update_image_info()
return self.width return self.width
security.declareProtected(Permissions.AccessContentsInformation, 'getHeight') security.declareProtected(Permissions.AccessContentsInformation, 'getHeight')
...@@ -169,7 +170,8 @@ class Image(TextConvertableMixin, File, OFSImage): ...@@ -169,7 +170,8 @@ class Image(TextConvertableMixin, File, OFSImage):
Tries to get the height from the image data. Tries to get the height from the image data.
""" """
self._upradeImage() self._upradeImage()
if self.get_size() and not self.height: self._update_image_info() if self.hasData() and not self.height:
self._update_image_info()
return self.height return self.height
security.declareProtected(Permissions.AccessContentsInformation, 'getContentType') security.declareProtected(Permissions.AccessContentsInformation, 'getContentType')
...@@ -289,9 +291,10 @@ class Image(TextConvertableMixin, File, OFSImage): ...@@ -289,9 +291,10 @@ class Image(TextConvertableMixin, File, OFSImage):
age = self._photos[(id,format)]._age() age = self._photos[(id,format)]._age()
else: else:
(photo_width, photo_height, bytes, age) = (None, None, None, None) (photo_width, photo_height, bytes, age) = (None, None, None, None)
image_size = self.getSizeFromImageDisplay(id)
displays.append({'id': id, displays.append({'id': id,
'width': self.getSizeFromImageDisplay(id)[0], 'width': image_size[0],
'height': self.getSizeFromImageDisplay(id)[1], 'height': image_size[1],
'photo_width': photo_width, 'photo_width': photo_width,
'photo_height': photo_height, 'photo_height': photo_height,
'bytes': bytes, 'bytes': bytes,
...@@ -309,7 +312,7 @@ class Image(TextConvertableMixin, File, OFSImage): ...@@ -309,7 +312,7 @@ class Image(TextConvertableMixin, File, OFSImage):
lookupExtension('name.%s' % format) lookupExtension('name.%s' % format)
mime_type = str(mime_type) mime_type = str(mime_type)
src_mimetype = self.getContentType() src_mimetype = self.getContentType()
content = '%s' % self.getData() content = self.getData()
portal_transforms = getToolByName(self, 'portal_transforms') portal_transforms = getToolByName(self, 'portal_transforms')
result = portal_transforms.convertToData(mime_type, content, result = portal_transforms.convertToData(mime_type, content,
object=self, context=self, object=self, context=self,
...@@ -472,9 +475,8 @@ class Image(TextConvertableMixin, File, OFSImage): ...@@ -472,9 +475,8 @@ class Image(TextConvertableMixin, File, OFSImage):
security.declareProtected('View', 'getSizeFromImageDisplay') security.declareProtected('View', 'getSizeFromImageDisplay')
def getSizeFromImageDisplay(self, image_display): def getSizeFromImageDisplay(self, image_display):
""" """Return the size for this image display,
Return the size for this image display, or None if this image display name or dimension of this image.
is not known.
""" """
if image_display in DEFAULT_DISPLAY_ID_LIST: if image_display in DEFAULT_DISPLAY_ID_LIST:
preference_tool = self.getPortalObject().portal_preferences preference_tool = self.getPortalObject().portal_preferences
...@@ -483,7 +485,7 @@ class Image(TextConvertableMixin, File, OFSImage): ...@@ -483,7 +485,7 @@ class Image(TextConvertableMixin, File, OFSImage):
height = preference_tool.getPreference(height_preference) height = preference_tool.getPreference(height_preference)
width = preference_tool.getPreference(width_preference) width = preference_tool.getPreference(width_preference)
return (width, height) return (width, height)
return None return self.getWidth(), self.getHeight()
def _setFile(self, *args, **kw): def _setFile(self, *args, **kw):
"""set the file content and reset image information. """set the file content and reset image information.
......
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