[MERGE] Merged with branch adding an avatar to res.users. This avatar will be used in OpenSocial feature.
bzr revid: tde@openerp.com-20120221154316-h2bwfjdkjt36emcs
This commit is contained in:
@@ -84,12 +84,18 @@
|
||||
<form string="Users">
|
||||
<field name="name" readonly="1"/>
|
||||
<newline/>
|
||||
<group colspan="2" col="2">
|
||||
<separator string="Preferences" colspan="2"/>
|
||||
<field name="view" readonly="0"/>
|
||||
<field name="context_lang" readonly="0"/>
|
||||
<field name="context_tz" readonly="0"/>
|
||||
<field name="menu_tips" readonly="0" groups="base.group_no_one"/>
|
||||
<group colspan="2" col="3">
|
||||
<group col="2" colspan="2">
|
||||
<separator string="Preferences" colspan="2"/>
|
||||
<field name="view" readonly="0"/>
|
||||
<field name="context_lang" readonly="0"/>
|
||||
<field name="context_tz" readonly="0"/>
|
||||
<field name="menu_tips" readonly="0" groups="base.group_no_one"/>
|
||||
</group>
|
||||
<group col="2" colspan="1">
|
||||
<separator string="Avatar" colspan="2"/>
|
||||
<field name="avatar" widget='image' nolabel="1" colspan="2"/>
|
||||
</group>
|
||||
</group>
|
||||
<group name="default_filters" colspan="2" col="2">
|
||||
<separator string="Default Filters" colspan="2"/>
|
||||
@@ -118,32 +124,36 @@
|
||||
</group>
|
||||
<notebook colspan="4">
|
||||
<page string="User">
|
||||
<group colspan="4" col="6">
|
||||
<!-- Second nested group to avoid misalignment with email prefs groups
|
||||
in simplified view -->
|
||||
<group colspan="6" col="6">
|
||||
<group col="2" colspan="2">
|
||||
<separator string="Preferences" colspan="2"/>
|
||||
<field name="context_lang"/>
|
||||
<field name="context_tz"/>
|
||||
<field name="menu_tips"/>
|
||||
<group colspan="4" col="7">
|
||||
<!-- Second nested group to avoid misalignment with email prefs groups
|
||||
in simplified view -->
|
||||
<group colspan="7" col="7">
|
||||
<group col="2" colspan="1">
|
||||
<separator string="Avatar" colspan="2"/>
|
||||
<field name="avatar_mini" widget='image' nolabel="1" colspan="2"/>
|
||||
</group>
|
||||
<group col="3" colspan="2">
|
||||
<separator string="Preferences" colspan="3"/>
|
||||
<field name="context_lang"/>
|
||||
<field name="context_tz"/>
|
||||
<field name="menu_tips"/>
|
||||
</group>
|
||||
<group name="default_filters" colspan="2" col="2">
|
||||
<separator string="Default Filters" colspan="2"/>
|
||||
<field name="company_id" required="1" context="{'user_preference': 0}" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
<group colspan="2" col="2" groups="base.group_extended">
|
||||
<separator string="Action" colspan="2"/>
|
||||
<field name="action_id"/>
|
||||
<field domain="[('usage','=','menu')]" name="menu_id" required="True"/>
|
||||
</group>
|
||||
</group>
|
||||
<group name="default_filters" colspan="2" col="2">
|
||||
<separator string="Default Filters" colspan="2"/>
|
||||
<field name="company_id" required="1" context="{'user_preference': 0}" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
<group colspan="2" col="2" groups="base.group_extended">
|
||||
<separator string="Action" colspan="2"/>
|
||||
<field name="action_id"/>
|
||||
<field domain="[('usage','=','menu')]" name="menu_id" required="True"/>
|
||||
<group colspan="7" col="2">
|
||||
<separator string="Email Preferences" colspan="2"/>
|
||||
<field name="user_email" widget="email"/>
|
||||
<field name="signature"/>
|
||||
</group>
|
||||
</group>
|
||||
<group colspan="6" col="2">
|
||||
<separator string="Email Preferences" colspan="2"/>
|
||||
<field name="user_email" widget="email"/>
|
||||
<field name="signature"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Access Rights">
|
||||
<field nolabel="1" name="groups_id"/>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user