[FIX] all image stuff on groups, users, partners

bzr revid: fp@tinyerp.com-20120903095527-7rk7wxuldv80fj4v
This commit is contained in:
Fabien Pinckaers
2012-09-03 11:55:27 +02:00
parent e3f1c26e6a
commit f29be675e2
5 changed files with 15 additions and 20 deletions
+12 -16
View File
@@ -225,14 +225,16 @@ class res_partner(osv.osv):
return [context['category_id']]
return False
def _get_default_image(self, cr, uid, is_company, context=None):
def _get_default_image(self, cr, uid, is_company, context=None, colorize=False):
if is_company:
image = open(openerp.modules.get_module_resource('base', 'static/src/img', 'company_image.png')).read()
else:
from PIL import Image
from StringIO import StringIO
from random import random
color = (int(random() * 192 + 32), int(random() * 192 + 32), int(random() * 192 + 32))
color = (255,255,255)
if colorize:
from random import random
color = (int(random() * 192 + 32), int(random() * 192 + 32), int(random() * 192 + 32))
face = Image.open(openerp.modules.get_module_resource('base', 'static/src/img', 'avatar.png'))
avatar = Image.new('RGB', face.size)
avatar.paste(color)
@@ -240,7 +242,7 @@ class res_partner(osv.osv):
buffer = StringIO()
avatar.save(buffer, 'PNG')
image = buffer.getvalue()
return tools.image_resize_image_big(image.encode('base64'))
return image.encode('base64')
_defaults = {
'active': True,
@@ -253,9 +255,7 @@ class res_partner(osv.osv):
'is_company': False,
'type': 'default',
'use_parent_address': True,
'image': lambda self, cr, uid, context: self._get_default_image(cr, uid, False, context),
'image_small': lambda self, cr, uid, context: self._get_default_image(cr, uid, False, context),
'image_medium': lambda self, cr, uid, context: self._get_default_image(cr, uid, False, context),
'image': lambda self, cr, uid, context: self._get_default_image(cr, uid, context.get('default_is_company', False), context),
}
def copy(self, cr, uid, id, default=None, context=None):
@@ -333,9 +333,6 @@ class res_partner(osv.osv):
domain_siblings = [('parent_id', '=', vals['parent_id']), ('use_parent_address', '=', True)]
update_ids = [vals['parent_id']] + self.search(cr, uid, domain_siblings, context=context)
self.update_address(cr, uid, update_ids, vals, context)
if 'image' not in vals :
image_value = self._get_default_image(cr, uid, vals.get('is_company', False) or context.get('default_is_company'), context)
vals.update(tools.image_get_resized_images(image_value, return_big=True))
return super(res_partner,self).create(cr, uid, vals, context=context)
def update_address(self, cr, uid, ids, vals, context=None):
@@ -379,18 +376,17 @@ class res_partner(osv.osv):
email_regex = re.compile('([a-zA-Z0-9._%-]+@[a-zA-Z0-9_-]+\.[a-zA-Z0-9._]{1,8})')
contact_regex_res = contact_regex.findall(name)
email_regex_res = email_regex.findall(name)
email = False
if contact_regex_res:
name = contact_regex_res[0][0].rstrip(' ') # remove extra spaces on the right
email = contact_regex_res[0][1]
rec_id = self.create(cr, uid, {self._rec_name: name, 'email': email}, context);
return self.name_get(cr, uid, [rec_id], context)[0]
elif email_regex_res:
email = '%s' % (email_regex_res[0])
rec_id = self.create(cr, uid, {self._rec_name: email, 'email': email}, context);
return self.name_get(cr, uid, [rec_id], context)[0]
else:
rec_id = super(res_partner, self).create(cr, uid, {self._rec_name: name}, context)
return self.name_get(cr, uid, [rec_id], context)[0]
pass
data = {self._rec_name: name, 'email': email}
rec_id = self.create(cr, uid, data, context);
return self.name_get(cr, uid, [rec_id], context)[0]
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
if not args:
+1
View File
@@ -251,6 +251,7 @@ class res_users(osv.osv):
'company_id': _get_company,
'company_ids': _get_companies,
'groups_id': _get_group,
'image': lambda self, cr, uid, context: self.pool.get('res.partner')._get_default_image(cr, uid, False, context, colorize=True),
}
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
+2 -4
View File
@@ -88,7 +88,7 @@
<form string="Users" version="7.0">
<field name="id" invisible="1"/>
<sheet>
<field name="image_medium" widget='image' class="oe_avatar oe_left"/>
<field name="image" widget='image' class="oe_avatar oe_left" options='{"preview_image": "image_medium"}'/>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<h1><field name="name"/></h1>
@@ -195,9 +195,7 @@
<field eval="18" name="priority"/>
<field name="arch" type="xml">
<form string="Users" version="7.0">
<div class="oe_right oe_avatar">
<field name="image_small" widget='image' class="oe_image_small"/>
</div>
<field name="image" widget='image' class="oe_right oe_avatar" options='{"preview_image": "image_small"}'/>
<h1>
<field name="name" readonly="1" class="oe_inline"/>
(<field name="login" readonly="1" class="oe_inline"/>)
Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 22 KiB