[MERGE] Merged with server/trunk.

bzr revid: tde@openerp.com-20120904075105-ljg3lgn6tf958kvd
This commit is contained in:
Thibault Delavallée 2012-09-04 09:51:05 +02:00
commit 1f84036086
9 changed files with 79 additions and 71 deletions

View File

@ -226,14 +226,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)
@ -241,7 +243,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,
@ -254,9 +256,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):
@ -334,9 +334,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):

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):

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

View File

@ -162,7 +162,7 @@ def initialize_sys_path():
return
ad_paths = map(lambda m: os.path.abspath(tools.ustr(m.strip())), tools.config['addons_path'].split(','))
ad_paths.append(_ad) # for get_module_path
ad_paths.append(os.path.abspath(_ad)) # for get_module_path
sys.meta_path.append(AddonsImportHook())
def get_module_path(module, downloaded=False, display_warning=True):
@ -283,25 +283,28 @@ def get_module_as_zip(modulename, b64enc=True, src=True):
def get_module_resource(module, *args):
"""Return the full path of a resource of the given module.
@param module: the module
@param args: the resource path components
:param module: module name
:param list(str) args: resource path components within module
@return: absolute path to the resource
:rtype: str
:return: absolute path to the resource
TODO name it get_resource_path
TODO make it available inside on osv object (self.get_resource_path)
"""
a = get_module_path(module)
if not a: return False
resource_path = opj(a, *args)
if zipfile.is_zipfile( a +'.zip') :
zip = zipfile.ZipFile( a + ".zip")
mod_path = get_module_path(module)
if not mod_path: return False
resource_path = opj(mod_path, *args)
if os.path.isdir(mod_path):
# the module is a directory - ignore zip behavior
if os.path.exists(resource_path):
return resource_path
elif zipfile.is_zipfile(mod_path + '.zip'):
zip = zipfile.ZipFile( mod_path + ".zip")
files = ['/'.join(f.split('/')[1:]) for f in zip.namelist()]
resource_path = '/'.join(args)
if resource_path in files:
return opj(a, resource_path)
elif os.path.exists(resource_path):
return resource_path
return opj(mod_path, resource_path)
return False
def get_module_icon(module):

View File

@ -186,7 +186,7 @@ class test_ir_sequence_generate(unittest2.TestCase):
cr = cursor()
f = lambda *a: registry('ir.sequence').next_by_code(cr, ADMIN_USER_ID, 'test_sequence_type_5', {})
assert all(str(x) == f() for x in xrange(1,1000))
assert all(str(x) == f() for x in xrange(1,10))
cr.commit()
cr.close()
@ -204,7 +204,7 @@ class test_ir_sequence_generate(unittest2.TestCase):
cr = cursor()
f = lambda *a: registry('ir.sequence').next_by_code(cr, ADMIN_USER_ID, 'test_sequence_type_6', {})
assert all(str(x) == f() for x in xrange(1,1000))
assert all(str(x) == f() for x in xrange(1,10))
cr.commit()
cr.close()

View File

@ -134,7 +134,7 @@ def file_open(name, mode="r", subdir='addons', pathinfo=False):
@param name name of the file
@param mode file open mode
@param subdir subdirectory
@param pathinfo if True returns tupple (fileobject, filepath)
@param pathinfo if True returns tuple (fileobject, filepath)
@return fileobject if pathinfo is False else (fileobject, filepath)
"""
@ -142,44 +142,60 @@ def file_open(name, mode="r", subdir='addons', pathinfo=False):
adps = addons.module.ad_paths
rtp = os.path.normcase(os.path.abspath(config['root_path']))
if name.replace(os.path.sep, '/').startswith('addons/'):
if os.path.isabs(name):
# It is an absolute path
# Is it below 'addons_path' or 'root_path'?
name = os.path.normcase(os.path.normpath(name))
for root in adps + [rtp]:
if name.startswith(root):
base = root.rstrip(os.sep)
name = name[len(base) + 1:]
break
else:
# It is outside the OpenERP root: skip zipfile lookup.
base, name = os.path.split(name)
return _fileopen(name, mode=mode, basedir=base, pathinfo=pathinfo)
if name.replace(os.sep, '/').startswith('addons/'):
subdir = 'addons'
name = name[7:]
name2 = name[7:]
elif subdir:
name = os.path.join(subdir, name)
if name.replace(os.sep, '/').startswith('addons/'):
subdir = 'addons'
name2 = name[7:]
else:
name2 = name
# First try to locate in addons_path
# First, try to locate in addons_path
if subdir:
subdir2 = subdir
if subdir2.replace(os.path.sep, '/').startswith('addons/'):
subdir2 = subdir2[7:]
subdir2 = (subdir2 != 'addons' or None) and subdir2
for adp in adps:
try:
if subdir2:
fn = os.path.join(adp, subdir2, name)
else:
fn = os.path.join(adp, name)
fn = os.path.normpath(fn)
fo = file_open(fn, mode=mode, subdir=None, pathinfo=pathinfo)
if pathinfo:
return fo, fn
return fo
return _fileopen(name2, mode=mode, basedir=adp,
pathinfo=pathinfo)
except IOError:
pass
if subdir:
name = os.path.join(rtp, subdir, name)
else:
name = os.path.join(rtp, name)
# Second, try to locate in root_path
return _fileopen(name, mode=mode, basedir=rtp, pathinfo=pathinfo)
name = os.path.normpath(name)
# Check for a zipfile in the path
head = name
def _fileopen(path, mode, basedir, pathinfo):
name = os.path.normpath(os.path.join(basedir, path))
# Give higher priority to module directories, which is
# a more common case than zipped modules.
if os.path.isfile(name):
fo = open(name, mode)
if pathinfo:
return (fo, name)
return fo
# Support for loading modules in zipped form.
# This will not work for zipped modules that are sitting
# outside of known addons paths.
head = os.path.normpath(path)
zipname = False
name2 = False
while True:
while os.sep in head:
head, tail = os.path.split(head)
if not tail:
break
@ -187,9 +203,10 @@ def file_open(name, mode="r", subdir='addons', pathinfo=False):
zipname = os.path.join(tail, zipname)
else:
zipname = tail
if zipfile.is_zipfile(head+'.zip'):
zpath = os.path.join(basedir, head + '.zip')
if zipfile.is_zipfile(zpath):
from cStringIO import StringIO
zfile = zipfile.ZipFile(head+'.zip')
zfile = zipfile.ZipFile(zpath)
try:
fo = StringIO()
fo.write(zfile.read(os.path.join(
@ -197,20 +214,14 @@ def file_open(name, mode="r", subdir='addons', pathinfo=False):
os.sep, '/')))
fo.seek(0)
if pathinfo:
return fo, name
return (fo, name)
return fo
except Exception:
name2 = os.path.normpath(os.path.join(head + '.zip', zipname))
pass
for i in (name2, name):
if i and os.path.isfile(i):
fo = file(i, mode)
if pathinfo:
return fo, i
return fo
if os.path.splitext(name)[1] == '.rml':
raise IOError, 'Report %s doesn\'t exist or deleted : ' %str(name)
raise IOError, 'File not found : %s' % name
# Not found
if name.endswith('.rml'):
raise IOError('Report %r doesn\'t exist or deleted' % name)
raise IOError('File not found: %s' % name)
#----------------------------------------------------------

View File

@ -811,8 +811,6 @@ class YamlInterpreter(object):
is_preceded_by_comment = self._log_node(node, is_preceded_by_comment)
try:
self._process_node(node)
except YamlImportException, e:
_logger.exception(e)
except Exception, e:
_logger.exception(e)
raise