Commit 9edf52e9 authored by Julien Muchembled's avatar Julien Muchembled

Fix bug #1311 (get sizes of image displays from preferences)

In getSizeFromImageDisplay, accessors must be used without default 0 parameter
because it would override the default value from property sheet,
and the user may not have overriden these values in his preferences.

Add a unit test to test that behaviour of preference accessor.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29505 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3bfb8c70
......@@ -505,14 +505,14 @@ class Image(File, OFSImage):
def getSizeFromImageDisplay(self, image_display):
"""
Return the size for this image display, or None if this image display name
is not known. If the preference is not set, (0, 0) is returned.
is not known.
"""
if image_display in default_displays_id_list:
preference_tool = self.getPortalObject().portal_preferences
height_preference = 'preferred_%s_image_height' % (image_display,)
width_preferece = 'preferred_%s_image_width' % (image_display,)
height = preference_tool.getPreference(height_preference, 0)
width = preference_tool.getPreference(width_preferece, 0)
width_preference = 'preferred_%s_image_width' % (image_display,)
height = preference_tool.getPreference(height_preference)
width = preference_tool.getPreference(width_preference)
return (height, width)
return None
......
......@@ -457,6 +457,10 @@ class TestPreferences(ERP5TypeTestCase):
preference_tool.getPreferredOoodocServerAddress('localhost'))
self.assertEqual(default_large_image_height,
preference_tool.getPreferredLargeImageHeight())
# Default value passed by parameter has priority over the default in the
# property sheet.
self.assertEqual(large_image_height,
preference_tool.getPreferredLargeImageHeight(large_image_height))
# Members can't add new system preferences
uf = self.getPortal().acl_users
......@@ -491,6 +495,8 @@ class TestPreferences(ERP5TypeTestCase):
preference_tool.getPreferredOoodocServerAddress('localhost'))
self.assertEqual(large_image_height,
preference_tool.getPreferredLargeImageHeight())
self.assertEqual(large_image_height,
preference_tool.getPreferredLargeImageHeight(0))
# check a user can't edit preference which are marked for manager
self.assertRaises(Unauthorized, user_pref.edit, preferred_ooodoc_server_address="localhost")
......
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