[IMP] Properly import files

bzr revid: fme@openerp.com-20140324151711-89mfg14573dpnh0p
This commit is contained in:
Fabien Meghazi 2014-03-24 16:17:11 +01:00
parent 9285813da9
commit 5e484ae892
1 changed files with 7 additions and 2 deletions

View File

@ -43,13 +43,14 @@ class view(osv.osv):
convert_file(cr, module, filename, idref, mode=mode, noupdate=noupdate, kind=kind, pathname=pathname)
path_static = opj(path, 'static')
ir_attach = self.pool['ir.attachment']
if os.path.isdir(path_static):
for root, _, files in os.walk(path_static):
for static_file in files:
full_path = opj(root, static_file)
with open(full_path, 'r') as fp:
data = fp.read().encode('base64')
url_path = full_path.split(path)[1].replace(os.path.sep, '/')
url_path = '/%s%s' % (module, full_path.split(path)[1].replace(os.path.sep, '/'))
url_path = url_path.decode(sys.getfilesystemencoding())
filename = os.path.split(url_path)[1]
values = dict(
@ -60,7 +61,11 @@ class view(osv.osv):
type='binary',
datas=data,
)
self.pool['ir.attachment'].create(cr, uid, values, context=context)
att_id = ir_attach.search(cr, uid, [('url', '=', url_path), ('type', '=', 'binary'), ('res_model', '=', 'ir.ui.view')], context=context)
if att_id:
ir_attach.write(cr, uid, att_id, values, context=context)
else:
ir_attach.create(cr, uid, values, context=context)
return True