[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
This commit is contained in:
Thibault Delavallée 2012-03-23 11:32:30 +01:00
parent cab93f9673
commit d67e232806
2 changed files with 6 additions and 6 deletions

View File

@ -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.

View File

@ -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."),