[MERGE] Merged with server/trunk.
bzr revid: tde@openerp.com-20120904075105-ljg3lgn6tf958kvd
This commit is contained in:
commit
1f84036086
|
@ -226,14 +226,16 @@ class res_partner(osv.osv):
|
||||||
return [context['category_id']]
|
return [context['category_id']]
|
||||||
return False
|
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:
|
if is_company:
|
||||||
image = open(openerp.modules.get_module_resource('base', 'static/src/img', 'company_image.png')).read()
|
image = open(openerp.modules.get_module_resource('base', 'static/src/img', 'company_image.png')).read()
|
||||||
else:
|
else:
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
from random import random
|
color = (255,255,255)
|
||||||
color = (int(random() * 192 + 32), int(random() * 192 + 32), int(random() * 192 + 32))
|
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'))
|
face = Image.open(openerp.modules.get_module_resource('base', 'static/src/img', 'avatar.png'))
|
||||||
avatar = Image.new('RGB', face.size)
|
avatar = Image.new('RGB', face.size)
|
||||||
avatar.paste(color)
|
avatar.paste(color)
|
||||||
|
@ -241,7 +243,7 @@ class res_partner(osv.osv):
|
||||||
buffer = StringIO()
|
buffer = StringIO()
|
||||||
avatar.save(buffer, 'PNG')
|
avatar.save(buffer, 'PNG')
|
||||||
image = buffer.getvalue()
|
image = buffer.getvalue()
|
||||||
return tools.image_resize_image_big(image.encode('base64'))
|
return image.encode('base64')
|
||||||
|
|
||||||
_defaults = {
|
_defaults = {
|
||||||
'active': True,
|
'active': True,
|
||||||
|
@ -254,9 +256,7 @@ class res_partner(osv.osv):
|
||||||
'is_company': False,
|
'is_company': False,
|
||||||
'type': 'default',
|
'type': 'default',
|
||||||
'use_parent_address': True,
|
'use_parent_address': True,
|
||||||
'image': 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),
|
||||||
'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),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def copy(self, cr, uid, id, default=None, context=None):
|
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)]
|
domain_siblings = [('parent_id', '=', vals['parent_id']), ('use_parent_address', '=', True)]
|
||||||
update_ids = [vals['parent_id']] + self.search(cr, uid, domain_siblings, context=context)
|
update_ids = [vals['parent_id']] + self.search(cr, uid, domain_siblings, context=context)
|
||||||
self.update_address(cr, uid, update_ids, vals, 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)
|
return super(res_partner,self).create(cr, uid, vals, context=context)
|
||||||
|
|
||||||
def update_address(self, cr, uid, ids, vals, context=None):
|
def update_address(self, cr, uid, ids, vals, context=None):
|
||||||
|
|
|
@ -251,6 +251,7 @@ class res_users(osv.osv):
|
||||||
'company_id': _get_company,
|
'company_id': _get_company,
|
||||||
'company_ids': _get_companies,
|
'company_ids': _get_companies,
|
||||||
'groups_id': _get_group,
|
'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):
|
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
|
||||||
|
|
|
@ -88,7 +88,7 @@
|
||||||
<form string="Users" version="7.0">
|
<form string="Users" version="7.0">
|
||||||
<field name="id" invisible="1"/>
|
<field name="id" invisible="1"/>
|
||||||
<sheet>
|
<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">
|
<div class="oe_title">
|
||||||
<label for="name" class="oe_edit_only"/>
|
<label for="name" class="oe_edit_only"/>
|
||||||
<h1><field name="name"/></h1>
|
<h1><field name="name"/></h1>
|
||||||
|
@ -195,9 +195,7 @@
|
||||||
<field eval="18" name="priority"/>
|
<field eval="18" name="priority"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="Users" version="7.0">
|
<form string="Users" version="7.0">
|
||||||
<div class="oe_right oe_avatar">
|
<field name="image" widget='image' class="oe_right oe_avatar" options='{"preview_image": "image_small"}'/>
|
||||||
<field name="image_small" widget='image' class="oe_image_small"/>
|
|
||||||
</div>
|
|
||||||
<h1>
|
<h1>
|
||||||
<field name="name" readonly="1" class="oe_inline"/>
|
<field name="name" readonly="1" class="oe_inline"/>
|
||||||
(<field name="login" 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 |
|
@ -162,7 +162,7 @@ def initialize_sys_path():
|
||||||
return
|
return
|
||||||
|
|
||||||
ad_paths = map(lambda m: os.path.abspath(tools.ustr(m.strip())), tools.config['addons_path'].split(','))
|
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())
|
sys.meta_path.append(AddonsImportHook())
|
||||||
|
|
||||||
def get_module_path(module, downloaded=False, display_warning=True):
|
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):
|
def get_module_resource(module, *args):
|
||||||
"""Return the full path of a resource of the given module.
|
"""Return the full path of a resource of the given module.
|
||||||
|
|
||||||
@param module: the module
|
:param module: module name
|
||||||
@param args: the resource path components
|
: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 name it get_resource_path
|
||||||
TODO make it available inside on osv object (self.get_resource_path)
|
TODO make it available inside on osv object (self.get_resource_path)
|
||||||
"""
|
"""
|
||||||
a = get_module_path(module)
|
mod_path = get_module_path(module)
|
||||||
if not a: return False
|
if not mod_path: return False
|
||||||
resource_path = opj(a, *args)
|
resource_path = opj(mod_path, *args)
|
||||||
if zipfile.is_zipfile( a +'.zip') :
|
if os.path.isdir(mod_path):
|
||||||
zip = zipfile.ZipFile( a + ".zip")
|
# 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()]
|
files = ['/'.join(f.split('/')[1:]) for f in zip.namelist()]
|
||||||
resource_path = '/'.join(args)
|
resource_path = '/'.join(args)
|
||||||
if resource_path in files:
|
if resource_path in files:
|
||||||
return opj(a, resource_path)
|
return opj(mod_path, resource_path)
|
||||||
elif os.path.exists(resource_path):
|
|
||||||
return resource_path
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_module_icon(module):
|
def get_module_icon(module):
|
||||||
|
|
|
@ -186,7 +186,7 @@ class test_ir_sequence_generate(unittest2.TestCase):
|
||||||
|
|
||||||
cr = cursor()
|
cr = cursor()
|
||||||
f = lambda *a: registry('ir.sequence').next_by_code(cr, ADMIN_USER_ID, 'test_sequence_type_5', {})
|
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.commit()
|
||||||
cr.close()
|
cr.close()
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ class test_ir_sequence_generate(unittest2.TestCase):
|
||||||
|
|
||||||
cr = cursor()
|
cr = cursor()
|
||||||
f = lambda *a: registry('ir.sequence').next_by_code(cr, ADMIN_USER_ID, 'test_sequence_type_6', {})
|
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.commit()
|
||||||
cr.close()
|
cr.close()
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ def file_open(name, mode="r", subdir='addons', pathinfo=False):
|
||||||
@param name name of the file
|
@param name name of the file
|
||||||
@param mode file open mode
|
@param mode file open mode
|
||||||
@param subdir subdirectory
|
@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)
|
@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
|
adps = addons.module.ad_paths
|
||||||
rtp = os.path.normcase(os.path.abspath(config['root_path']))
|
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'
|
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:
|
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:
|
for adp in adps:
|
||||||
try:
|
try:
|
||||||
if subdir2:
|
return _fileopen(name2, mode=mode, basedir=adp,
|
||||||
fn = os.path.join(adp, subdir2, name)
|
pathinfo=pathinfo)
|
||||||
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
|
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if subdir:
|
# Second, try to locate in root_path
|
||||||
name = os.path.join(rtp, subdir, name)
|
return _fileopen(name, mode=mode, basedir=rtp, pathinfo=pathinfo)
|
||||||
else:
|
|
||||||
name = os.path.join(rtp, name)
|
|
||||||
|
|
||||||
name = os.path.normpath(name)
|
|
||||||
|
|
||||||
# Check for a zipfile in the path
|
def _fileopen(path, mode, basedir, pathinfo):
|
||||||
head = name
|
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
|
zipname = False
|
||||||
name2 = False
|
while os.sep in head:
|
||||||
while True:
|
|
||||||
head, tail = os.path.split(head)
|
head, tail = os.path.split(head)
|
||||||
if not tail:
|
if not tail:
|
||||||
break
|
break
|
||||||
|
@ -187,9 +203,10 @@ def file_open(name, mode="r", subdir='addons', pathinfo=False):
|
||||||
zipname = os.path.join(tail, zipname)
|
zipname = os.path.join(tail, zipname)
|
||||||
else:
|
else:
|
||||||
zipname = tail
|
zipname = tail
|
||||||
if zipfile.is_zipfile(head+'.zip'):
|
zpath = os.path.join(basedir, head + '.zip')
|
||||||
|
if zipfile.is_zipfile(zpath):
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
zfile = zipfile.ZipFile(head+'.zip')
|
zfile = zipfile.ZipFile(zpath)
|
||||||
try:
|
try:
|
||||||
fo = StringIO()
|
fo = StringIO()
|
||||||
fo.write(zfile.read(os.path.join(
|
fo.write(zfile.read(os.path.join(
|
||||||
|
@ -197,20 +214,14 @@ def file_open(name, mode="r", subdir='addons', pathinfo=False):
|
||||||
os.sep, '/')))
|
os.sep, '/')))
|
||||||
fo.seek(0)
|
fo.seek(0)
|
||||||
if pathinfo:
|
if pathinfo:
|
||||||
return fo, name
|
return (fo, name)
|
||||||
return fo
|
return fo
|
||||||
except Exception:
|
except Exception:
|
||||||
name2 = os.path.normpath(os.path.join(head + '.zip', zipname))
|
|
||||||
pass
|
pass
|
||||||
for i in (name2, name):
|
# Not found
|
||||||
if i and os.path.isfile(i):
|
if name.endswith('.rml'):
|
||||||
fo = file(i, mode)
|
raise IOError('Report %r doesn\'t exist or deleted' % name)
|
||||||
if pathinfo:
|
raise IOError('File not found: %s' % name)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
|
|
|
@ -811,8 +811,6 @@ class YamlInterpreter(object):
|
||||||
is_preceded_by_comment = self._log_node(node, is_preceded_by_comment)
|
is_preceded_by_comment = self._log_node(node, is_preceded_by_comment)
|
||||||
try:
|
try:
|
||||||
self._process_node(node)
|
self._process_node(node)
|
||||||
except YamlImportException, e:
|
|
||||||
_logger.exception(e)
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
_logger.exception(e)
|
_logger.exception(e)
|
||||||
raise
|
raise
|
||||||
|
|
Loading…
Reference in New Issue