From d48b3bdb6b5370af71efe1cc2557eaea68282581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 23 Mar 2012 10:08:21 +0100 Subject: [PATCH 01/10] [IMP] Improved code: renamed avatar->avatar_stored (stored in database); avatar_mini->avatar (interface field taht must be used); removed unnecessary comments; added help string on added fields to help understanding how the functionality works. bzr revid: tde@openerp.com-20120323090821-rse7y3i1qpp8tbky --- openerp/addons/base/base_update.xml | 4 ++-- openerp/addons/base/res/res_users.py | 27 ++++++++++++--------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/openerp/addons/base/base_update.xml b/openerp/addons/base/base_update.xml index 5d6f214c0a9..85d92106fc8 100644 --- a/openerp/addons/base/base_update.xml +++ b/openerp/addons/base/base_update.xml @@ -94,7 +94,7 @@ - + @@ -130,7 +130,7 @@ - + diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index c98c3ab8f5a..55e251b9af0 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -35,10 +35,8 @@ from tools.translate import _ import openerp import openerp.exceptions -# for avatar resizing import io, StringIO from PIL import Image -# for default avatar choice import random _logger = logging.getLogger(__name__) @@ -217,11 +215,11 @@ class users(osv.osv): extended_users = group_obj.read(cr, uid, extended_group_id, ['users'], context=context)['users'] return dict(zip(ids, ['extended' if user in extended_users else 'simple' for user in ids])) - def onchange_avatar_mini(self, cr, uid, ids, value, context=None): - return {'value': {'avatar': value, 'avatar_mini': self._avatar_resize(cr, uid, value) } } + def onchange_avatar(self, cr, uid, ids, value, context=None): + return {'value': {'avatar_stored': value, 'avatar': self._avatar_resize(cr, uid, value, context=context) } } - def _set_avatar_mini(self, cr, uid, id, name, value, args, context=None): - return self.write(cr, uid, [id], {'avatar': value}, context=context) + def _set_avatar(self, cr, uid, id, name, value, args, context=None): + return self.write(cr, uid, [id], {'avatar_stored': value}, context=context) def _avatar_resize(self, cr, uid, avatar, context=None): image_stream = io.BytesIO(avatar.decode('base64')) @@ -231,13 +229,13 @@ class users(osv.osv): img.save(img_stream, "JPEG") return img_stream.getvalue().encode('base64') - def _get_avatar_mini(self, cr, uid, ids, name, args, context=None): + def _get_avatar(self, cr, uid, ids, name, args, context=None): result = {} for user in self.browse(cr, uid, ids, context=context): if not user.avatar: result[user.id] = False else: - result[user.id] = self._avatar_resize(cr, uid, user.avatar) + result[user.id] = self._avatar_resize(cr, uid, user.avatar_stored) return result def _set_new_password(self, cr, uid, id, name, value, args, context=None): @@ -269,11 +267,11 @@ class users(osv.osv): "otherwise leave empty. After a change of password, the user has to login again."), 'user_email': fields.char('Email', size=64), 'signature': fields.text('Signature', size=64), - 'avatar': fields.binary('User Avatar'), - 'avatar_mini': fields.function(_get_avatar_mini, fnct_inv=_set_avatar_mini, string='User Avatar Mini', type="binary", + 'avatar_stored': fields.binary('Stored avatar', help="This field holds the image used as avatar for the user. The avatar field is used as an interface to access this field. The image is base64 encoded, and PIL-supported."), + 'avatar': fields.function(_get_avatar, fnct_inv=_set_avatar, string='Avatar', type="binary", store = { - 'res.users': (lambda self, cr, uid, ids, c={}: ids, ['avatar'], 10), - }), + 'res.users': (lambda self, cr, uid, ids, c={}: ids, ['avatar_stored'], 10), + }, help="Image used as avatar for the user. It is automatically resized as a 180x150 px image."), 'active': fields.boolean('Active'), 'action_id': fields.many2one('ir.actions.actions', 'Home Action', help="If specified, this action will be opened at logon for this user, in addition to the standard menu."), 'menu_id': fields.many2one('ir.actions.actions', 'Menu Action', help="If specified, the action will replace the standard menu for this user."), @@ -386,15 +384,14 @@ class users(osv.osv): return result def _get_avatar(self, cr, uid, context=None): - # default avatar file name: avatar0 -> avatar6, choose randomly - random.seed() + # default avatar file name: avatar0 -> avatar6.jpg, choose randomly avatar_path = openerp.modules.get_module_resource('base', 'images', 'avatar%d.jpg' % random.randint(0, 6)) return self._avatar_resize(cr, uid, open(avatar_path, 'rb').read().encode('base64')) _defaults = { 'password' : '', 'context_lang': 'en_US', - 'avatar_mini': _get_avatar, + 'avatar': _get_avatar, 'active' : True, 'menu_id': _get_menu, 'company_id': _get_company, From d7be1e92d03f26241a1084c4faaccce66fc9aa89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 23 Mar 2012 10:15:08 +0100 Subject: [PATCH 02/10] [DOC] Updated doc to match last revision. bzr revid: tde@openerp.com-20120323091508-2m01y3hj9vw49ofk --- doc/api/user_img_specs.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/api/user_img_specs.rst b/doc/api/user_img_specs.rst index d2bce64f142..ea1d39c26a8 100644 --- a/doc/api/user_img_specs.rst +++ b/doc/api/user_img_specs.rst @@ -2,8 +2,8 @@ User avatar =========== This revision adds an avatar for users. This replaces the use of gravatar to emulate avatars, used in views like the tasks kanban view. Two fields have been added to the res.users model: - - avatar, a binary field holding the image - - avatar_mini, a binary field holding an automatically resized version of the avatar. Dimensions of the resized avatar are 180x150. -User avatar has to be used everywhere an image depicting users is likely to be used, by using the avatar_mini field. + - avatar_stored, a binary field holding the image. It is base-64 encoded, and PIL-supported. + - avatar, a function binary field holding an automatically resized version of the avatar. Dimensions of the resized avatar are 180x150. This field is used as an inteface to get and set the user avatar. When changing this field in a view, the new image is automatically resized, and stored in the avatar_stored field. Note that the value is stored on another field, because otherwise it would imply to write on the function field, which currently using OpenERP 6.1 can lead to issues. +User avatar has to be used everywhere an image depicting users is likely to be used, by using the avatar field. An avatar field has been added to the users form view, as well as in Preferences. When creating a new user, a default avatar is chosen among 6 possible default images. From 6e0643868e8f245fd923d5d010901a2cefe0553a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 23 Mar 2012 10:17:47 +0100 Subject: [PATCH 03/10] [FIX] Forgot to update a field name. bzr revid: tde@openerp.com-20120323091747-i2dhjhy5witysd7s --- openerp/addons/base/res/res_users.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index 55e251b9af0..1c3dda89878 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -222,7 +222,7 @@ class users(osv.osv): return self.write(cr, uid, [id], {'avatar_stored': value}, context=context) def _avatar_resize(self, cr, uid, avatar, context=None): - image_stream = io.BytesIO(avatar.decode('base64')) + image_stream = io.BytesIO(avatar_stored.decode('base64')) img = Image.open(image_stream) img.thumbnail((180, 150), Image.ANTIALIAS) img_stream = StringIO.StringIO() From 0e95e0cf92bef425511eb26d7dbbc1d5488a2dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 23 Mar 2012 11:05:13 +0100 Subject: [PATCH 04/10] [FIX] Fixed the last fix. Also cleaned a bit the code. bzr revid: tde@openerp.com-20120323100513-m2n5n3jtxz8zo1yl --- openerp/addons/base/res/res_users.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index 6f28881b412..3827e5ef8c5 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -219,13 +219,13 @@ class users(osv.osv): return dict(zip(ids, ['extended' if user in extended_users else 'simple' for user in ids])) def onchange_avatar(self, cr, uid, ids, value, context=None): - return {'value': {'avatar_stored': value, 'avatar': self._avatar_resize(cr, uid, value, context=context) } } + return {'value': {'avatar_stored': self._avatar_resize(cr, uid, value, context=context), 'avatar': self._avatar_resize(cr, uid, value, context=context) } } def _set_avatar(self, cr, uid, id, name, value, args, context=None): return self.write(cr, uid, [id], {'avatar_stored': value}, context=context) def _avatar_resize(self, cr, uid, avatar, context=None): - image_stream = io.BytesIO(avatar_stored.decode('base64')) + image_stream = io.BytesIO(avatar.decode('base64')) img = Image.open(image_stream) img.thumbnail((180, 150), Image.ANTIALIAS) img_stream = StringIO.StringIO() @@ -233,11 +233,9 @@ class users(osv.osv): return img_stream.getvalue().encode('base64') def _get_avatar(self, cr, uid, ids, name, args, context=None): - result = {} + result = dict.fromkeys(ids, False) for user in self.browse(cr, uid, ids, context=context): - if not user.avatar: - result[user.id] = False - else: + if user.avatar_stored: result[user.id] = self._avatar_resize(cr, uid, user.avatar_stored) return result From cab93f96739a782b2775923921b1bf85c3f877ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 23 Mar 2012 11:14:14 +0100 Subject: [PATCH 05/10] [IMP] Added height and width parameters to the resize method. Propagated context. bzr revid: tde@openerp.com-20120323101414-28xbjkfhk03f5whe --- openerp/addons/base/res/res_users.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index 3827e5ef8c5..e8e0e68b8d9 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -219,15 +219,15 @@ class users(osv.osv): return dict(zip(ids, ['extended' if user in extended_users else 'simple' for user in ids])) def onchange_avatar(self, cr, uid, ids, value, context=None): - return {'value': {'avatar_stored': self._avatar_resize(cr, uid, value, context=context), 'avatar': self._avatar_resize(cr, uid, value, context=context) } } + return {'value': {'avatar_stored': self._avatar_resize(cr, uid, value, 360, 300, context=context), 'avatar': self._avatar_resize(cr, uid, value, context=context) } } def _set_avatar(self, cr, uid, id, name, value, args, context=None): return self.write(cr, uid, [id], {'avatar_stored': value}, context=context) - def _avatar_resize(self, cr, uid, avatar, context=None): + def _avatar_resize(self, cr, uid, avatar, height=180, width=150, context=None): image_stream = io.BytesIO(avatar.decode('base64')) img = Image.open(image_stream) - img.thumbnail((180, 150), Image.ANTIALIAS) + img.thumbnail((height, width), Image.ANTIALIAS) img_stream = StringIO.StringIO() img.save(img_stream, "JPEG") return img_stream.getvalue().encode('base64') @@ -236,7 +236,7 @@ class users(osv.osv): result = dict.fromkeys(ids, False) for user in self.browse(cr, uid, ids, context=context): if user.avatar_stored: - result[user.id] = self._avatar_resize(cr, uid, user.avatar_stored) + result[user.id] = self._avatar_resize(cr, uid, user.avatar_stored, context=context) return result def _set_new_password(self, cr, uid, id, name, value, args, context=None): @@ -387,7 +387,7 @@ class users(osv.osv): def _get_avatar(self, cr, uid, context=None): # default avatar file name: avatar0 -> avatar6.jpg, choose randomly avatar_path = openerp.modules.get_module_resource('base', 'images', 'avatar%d.jpg' % random.randint(0, 6)) - return self._avatar_resize(cr, uid, open(avatar_path, 'rb').read().encode('base64')) + return self._avatar_resize(cr, uid, open(avatar_path, 'rb').read().encode('base64'), context=context) _defaults = { 'password' : '', From d67e232806183343d743266782894f4d865af17e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 23 Mar 2012 11:32:30 +0100 Subject: [PATCH 06/10] [IMP] Improved comments and doc. Note that now avatar_stored stores a bigger version of the avatar, in case a bigger image must be used. bzr revid: tde@openerp.com-20120323103230-lcpbl1e9qhidivz7 --- doc/api/user_img_specs.rst | 4 ++-- openerp/addons/base/res/res_users.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/api/user_img_specs.rst b/doc/api/user_img_specs.rst index ea1d39c26a8..5a5b84422e0 100644 --- a/doc/api/user_img_specs.rst +++ b/doc/api/user_img_specs.rst @@ -2,8 +2,8 @@ User avatar =========== This revision adds an avatar for users. This replaces the use of gravatar to emulate avatars, used in views like the tasks kanban view. Two fields have been added to the res.users model: - - avatar_stored, a binary field holding the image. It is base-64 encoded, and PIL-supported. - - avatar, a function binary field holding an automatically resized version of the avatar. Dimensions of the resized avatar are 180x150. This field is used as an inteface to get and set the user avatar. When changing this field in a view, the new image is automatically resized, and stored in the avatar_stored field. Note that the value is stored on another field, because otherwise it would imply to write on the function field, which currently using OpenERP 6.1 can lead to issues. + - avatar_stored, a binary field holding the image. It is base-64 encoded, and PIL-supported. Images stored are resized to 540x450 px, to limitate the binary field size. + - avatar, a function binary field holding an automatically resized version of the avatar_stored field. Dimensions of the resized avatar are 180x150. This field is used as an inteface to get and set the user avatar. When changing this field in a view, the new image is automatically resized, and stored in the avatar_stored field. Note that the value is stored on another field, because otherwise it would imply to write on the function field, which currently using OpenERP 6.1 can lead to issues. User avatar has to be used everywhere an image depicting users is likely to be used, by using the avatar field. An avatar field has been added to the users form view, as well as in Preferences. When creating a new user, a default avatar is chosen among 6 possible default images. diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index e8e0e68b8d9..d08aca91bb1 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -219,10 +219,10 @@ class users(osv.osv): return dict(zip(ids, ['extended' if user in extended_users else 'simple' for user in ids])) def onchange_avatar(self, cr, uid, ids, value, context=None): - return {'value': {'avatar_stored': self._avatar_resize(cr, uid, value, 360, 300, context=context), 'avatar': self._avatar_resize(cr, uid, value, context=context) } } + return {'value': {'avatar_stored': self._avatar_resize(cr, uid, value, 540, 450, context=context), 'avatar': self._avatar_resize(cr, uid, value, context=context) } } def _set_avatar(self, cr, uid, id, name, value, args, context=None): - return self.write(cr, uid, [id], {'avatar_stored': value}, context=context) + return self.write(cr, uid, [id], {'avatar_stored': self._avatar_resize(cr, uid, value, 540, 450, context=context)}, context=context) def _avatar_resize(self, cr, uid, avatar, height=180, width=150, context=None): image_stream = io.BytesIO(avatar.decode('base64')) @@ -268,11 +268,11 @@ class users(osv.osv): "otherwise leave empty. After a change of password, the user has to login again."), 'user_email': fields.char('Email', size=64), 'signature': fields.text('Signature', size=64), - 'avatar_stored': fields.binary('Stored avatar', help="This field holds the image used as avatar for the user. The avatar field is used as an interface to access this field. The image is base64 encoded, and PIL-supported."), + 'avatar_stored': fields.binary('Stored avatar', help="This field holds the image used as avatar for the user. The avatar field is used as an interface to access this field. The image is base64 encoded, and PIL-supported. It is stored as a 540x450 px image, incase a bigger image must be used."), 'avatar': fields.function(_get_avatar, fnct_inv=_set_avatar, string='Avatar', type="binary", store = { 'res.users': (lambda self, cr, uid, ids, c={}: ids, ['avatar_stored'], 10), - }, help="Image used as avatar for the user. It is automatically resized as a 180x150 px image."), + }, help="Image used as avatar for the user. It is automatically resized as a 180x150 px image. This field serves as an interface to the avatar_stored field."), 'active': fields.boolean('Active'), 'action_id': fields.many2one('ir.actions.actions', 'Home Action', help="If specified, this action will be opened at logon for this user, in addition to the standard menu."), 'menu_id': fields.many2one('ir.actions.actions', 'Menu Action', help="If specified, the action will replace the standard menu for this user."), From 10eba844ba69769ef5efafa13f00862c82e4d743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 23 Mar 2012 12:05:21 +0100 Subject: [PATCH 07/10] [IMP] Reordered imports (alaphabetical order); avatar_stored->avatar_big, clearer field name bzr revid: tde@openerp.com-20120323110521-rna7hh5alr0as04c --- openerp/addons/base/res/res_users.py | 37 ++++++++++++++-------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index d08aca91bb1..5c52497219a 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -25,22 +25,21 @@ from functools import partial import pytz -import netsvc -import pooler -import tools -from osv import fields,osv -from osv.orm import browse_record -from service import security -from tools.translate import _ -import openerp -import openerp.exceptions +import io, StringIO from lxml import etree from lxml.builder import E - - -import io, StringIO +import netsvc +import openerp +import openerp.exceptions +from osv import fields,osv +from osv.orm import browse_record from PIL import Image +import pooler import random +from service import security +import tools +from tools.translate import _ + _logger = logging.getLogger(__name__) @@ -219,10 +218,10 @@ class users(osv.osv): return dict(zip(ids, ['extended' if user in extended_users else 'simple' for user in ids])) def onchange_avatar(self, cr, uid, ids, value, context=None): - return {'value': {'avatar_stored': self._avatar_resize(cr, uid, value, 540, 450, context=context), 'avatar': self._avatar_resize(cr, uid, value, context=context) } } + return {'value': {'avatar_big': self._avatar_resize(cr, uid, value, 540, 450, context=context), 'avatar': self._avatar_resize(cr, uid, value, context=context) } } def _set_avatar(self, cr, uid, id, name, value, args, context=None): - return self.write(cr, uid, [id], {'avatar_stored': self._avatar_resize(cr, uid, value, 540, 450, context=context)}, context=context) + return self.write(cr, uid, [id], {'avatar_big': self._avatar_resize(cr, uid, value, 540, 450, context=context)}, context=context) def _avatar_resize(self, cr, uid, avatar, height=180, width=150, context=None): image_stream = io.BytesIO(avatar.decode('base64')) @@ -235,8 +234,8 @@ class users(osv.osv): def _get_avatar(self, cr, uid, ids, name, args, context=None): result = dict.fromkeys(ids, False) for user in self.browse(cr, uid, ids, context=context): - if user.avatar_stored: - result[user.id] = self._avatar_resize(cr, uid, user.avatar_stored, context=context) + if user.avatar_big: + result[user.id] = self._avatar_resize(cr, uid, user.avatar_big, context=context) return result def _set_new_password(self, cr, uid, id, name, value, args, context=None): @@ -268,11 +267,11 @@ class users(osv.osv): "otherwise leave empty. After a change of password, the user has to login again."), 'user_email': fields.char('Email', size=64), 'signature': fields.text('Signature', size=64), - 'avatar_stored': fields.binary('Stored avatar', help="This field holds the image used as avatar for the user. The avatar field is used as an interface to access this field. The image is base64 encoded, and PIL-supported. It is stored as a 540x450 px image, incase a bigger image must be used."), + 'avatar_big': fields.binary('Big-sized avatar', help="This field holds the image used as avatar for the user. The avatar field is used as an interface to access this field. The image is base64 encoded, and PIL-supported. It is stored as a 540x450 px image, in case a bigger image must be used."), 'avatar': fields.function(_get_avatar, fnct_inv=_set_avatar, string='Avatar', type="binary", store = { - 'res.users': (lambda self, cr, uid, ids, c={}: ids, ['avatar_stored'], 10), - }, help="Image used as avatar for the user. It is automatically resized as a 180x150 px image. This field serves as an interface to the avatar_stored field."), + 'res.users': (lambda self, cr, uid, ids, c={}: ids, ['avatar_big'], 10), + }, help="Image used as avatar for the user. It is automatically resized as a 180x150 px image. This field serves as an interface to the avatar_big field."), 'active': fields.boolean('Active'), 'action_id': fields.many2one('ir.actions.actions', 'Home Action', help="If specified, this action will be opened at logon for this user, in addition to the standard menu."), 'menu_id': fields.many2one('ir.actions.actions', 'Menu Action', help="If specified, the action will replace the standard menu for this user."), From 4a2b5a72e5889fc0511414f2f9760facc3348d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 23 Mar 2012 12:10:29 +0100 Subject: [PATCH 08/10] [DOC] Updated doc. bzr revid: tde@openerp.com-20120323111029-6h8je23ywv61123s --- doc/api/user_img_specs.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/api/user_img_specs.rst b/doc/api/user_img_specs.rst index 5a5b84422e0..4ee97999aca 100644 --- a/doc/api/user_img_specs.rst +++ b/doc/api/user_img_specs.rst @@ -2,8 +2,8 @@ User avatar =========== This revision adds an avatar for users. This replaces the use of gravatar to emulate avatars, used in views like the tasks kanban view. Two fields have been added to the res.users model: - - avatar_stored, a binary field holding the image. It is base-64 encoded, and PIL-supported. Images stored are resized to 540x450 px, to limitate the binary field size. - - avatar, a function binary field holding an automatically resized version of the avatar_stored field. Dimensions of the resized avatar are 180x150. This field is used as an inteface to get and set the user avatar. When changing this field in a view, the new image is automatically resized, and stored in the avatar_stored field. Note that the value is stored on another field, because otherwise it would imply to write on the function field, which currently using OpenERP 6.1 can lead to issues. -User avatar has to be used everywhere an image depicting users is likely to be used, by using the avatar field. + - avatar_big, a binary field holding the image. It is base-64 encoded, and PIL-supported. Images stored are resized to 540x450 px, to limitate the binary field size. + - avatar, a function binary field holding an automatically resized version of the avatar_big field. It is also base-64 encoded, and PIL-supported. Dimensions of the resized avatar are 180x150. This field is used as an inteface to get and set the user avatar. +When changing the avatar through the avatar function field, the new image is automatically resized to 540x450, and stored in the avatar_big field. This triggers the function field, that will compute a 180x150 resized version of the image. An avatar field has been added to the users form view, as well as in Preferences. When creating a new user, a default avatar is chosen among 6 possible default images. From 31e186687e443767fe2f2a11c3d31a412ad35ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 23 Mar 2012 14:32:46 +0100 Subject: [PATCH 09/10] [FIX] Fixed crash when clearing avatar in form view. However, clearing means a new default avatar will be chosen. bzr revid: tde@openerp.com-20120323133246-78z4fszbqcvir16h --- openerp/addons/base/res/res_users.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index 5c52497219a..65e514fcb31 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -218,9 +218,13 @@ class users(osv.osv): return dict(zip(ids, ['extended' if user in extended_users else 'simple' for user in ids])) def onchange_avatar(self, cr, uid, ids, value, context=None): - return {'value': {'avatar_big': self._avatar_resize(cr, uid, value, 540, 450, context=context), 'avatar': self._avatar_resize(cr, uid, value, context=context) } } + if not value: + return {'value': {'avatar_big': value, 'avatar': value} } + return {'value': {'avatar_big': self._avatar_resize(cr, uid, value, 540, 450, context=context), 'avatar': self._avatar_resize(cr, uid, value, context=context)} } def _set_avatar(self, cr, uid, id, name, value, args, context=None): + if not value: + return {'value': {'avatar_big': value, 'avatar': value} } return self.write(cr, uid, [id], {'avatar_big': self._avatar_resize(cr, uid, value, 540, 450, context=context)}, context=context) def _avatar_resize(self, cr, uid, avatar, height=180, width=150, context=None): From 14609fa2edc5da5f455c9deae31cc9b412614cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 23 Mar 2012 15:02:51 +0100 Subject: [PATCH 10/10] [FIX] Fix of the last fix. Should avoid fixing on Friday. bzr revid: tde@openerp.com-20120323140251-wki6runit0juqlwg --- openerp/addons/base/res/res_users.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index 65e514fcb31..b8a4306b137 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -224,8 +224,10 @@ class users(osv.osv): def _set_avatar(self, cr, uid, id, name, value, args, context=None): if not value: - return {'value': {'avatar_big': value, 'avatar': value} } - return self.write(cr, uid, [id], {'avatar_big': self._avatar_resize(cr, uid, value, 540, 450, context=context)}, context=context) + vals = {'avatar_big': value} + else: + vals = {'avatar_big': self._avatar_resize(cr, uid, value, 540, 450, context=context)} + return self.write(cr, uid, [id], vals, context=context) def _avatar_resize(self, cr, uid, avatar, height=180, width=150, context=None): image_stream = io.BytesIO(avatar.decode('base64'))