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