diff --git a/openerp/addons/base/base_update.xml b/openerp/addons/base/base_update.xml index c5594f76e22..0eef0a0f4cb 100644 --- a/openerp/addons/base/base_update.xml +++ b/openerp/addons/base/base_update.xml @@ -84,12 +84,18 @@
- - - - - - + + + + + + + + + + + + @@ -118,32 +124,36 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + - - - - - - diff --git a/openerp/addons/base/images/photo.png b/openerp/addons/base/images/photo.png new file mode 100644 index 00000000000..1d124127b2b Binary files /dev/null and b/openerp/addons/base/images/photo.png differ diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index f148813ae05..7936ec2f5c9 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -35,6 +35,9 @@ from tools.translate import _ import openerp import openerp.exceptions +import io, StringIO +from PIL import Image + _logger = logging.getLogger(__name__) class groups(osv.osv): @@ -200,6 +203,24 @@ class users(osv.osv): self.write(cr, uid, ids, {'groups_id': [(4, extended_group_id)]}, context=context) return True + def _get_avatar_mini(self, cr, uid, ids, name, args, context=None): + result = {} + for obj in self.browse(cr, uid, ids, context=context): + if not obj.avatar: + result[obj.id] = False + continue + + image_stream = io.BytesIO(obj.avatar.decode('base64')) + img = Image.open(image_stream) + img.thumbnail((180, 150), Image.ANTIALIAS) + img_stream = StringIO.StringIO() + img.save(img_stream, "JPEG") + result[obj.id] = img_stream.getvalue().encode('base64') + return result + + def _set_avatar_mini(self, cr, uid, id, name, value, args, context=None): + self.write(cr, uid, [id], {'avatar': value}, context=context) + return True def _get_interface_type(self, cr, uid, ids, name, args, context=None): """Implementation of 'view' function field getter, returns the type of interface of the users. @@ -241,6 +262,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", + store = { + 'res.users': (lambda self, cr, uid, ids, c={}: ids, ['avatar'], 10), + }), '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."), @@ -352,9 +378,14 @@ class users(osv.osv): pass return result + def _get_avatar(self, cr, uid, context=None): + avatar_path = openerp.modules.get_module_resource('base','images','photo.png') + return open(avatar_path, 'rb').read().encode('base64') + _defaults = { 'password' : '', 'context_lang': 'en_US', + 'avatar': _get_avatar, 'active' : True, 'menu_id': _get_menu, 'company_id': _get_company,