From f411fef90cfb1a776e18d0ebcdb8c4c0ac3ef555 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Wed, 23 Sep 2015 12:58:36 +0200 Subject: [PATCH] [FIX] ir_ui_view: fix case where arch_fs is empty if arch_fs had no content, finditer with none was crashing. Use re.sub now, since it's the purpose of _resolve_external_ids function. --- openerp/addons/base/ir/ir_ui_view.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/openerp/addons/base/ir/ir_ui_view.py b/openerp/addons/base/ir/ir_ui_view.py index da14b2ef65f..d19e3e7dae2 100644 --- a/openerp/addons/base/ir/ir_ui_view.py +++ b/openerp/addons/base/ir/ir_ui_view.py @@ -154,21 +154,14 @@ class view(osv.osv): result.update(map(itemgetter('res_id', 'id'), data_ids)) return result - def _convert(self, cr, uid, s, view): - matches = re.finditer('[^%]%\((.*?)\)[ds]', s) - done = [] - for m in matches: - found = m.group()[1:] - if found in done: - continue - done.append(found) - xmlid = m.groups()[0] + def _resolve_external_ids(self, cr, uid, view, arch_fs): + def replacer(m): + xmlid = m.group('xmlid') if '.' not in xmlid: mod = view.get_external_id(cr, uid).get(view.id).split('.')[0] xmlid = '%s.%s' % (mod, xmlid) - res = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, xmlid) - s = s.replace(found, str(res)) - return s + return m.group('prefix') + str(self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, xmlid)) + return re.sub('(?P[^%])%\((?P.*?)\)[ds]', replacer, arch_fs) def _arch_get(self, cr, uid, ids, name, arg, context=None): result = {} @@ -180,7 +173,7 @@ class view(osv.osv): fullpath = get_resource_path(*view.arch_fs.split('/')) arch_fs = get_view_arch_from_file(fullpath, view.xml_id) # replace %(xml_id)s, %(xml_id)d, %%(xml_id)s, %%(xml_id)d by the res_id - arch_fs = self._convert(cr, uid, arch_fs, view) + arch_fs = arch_fs and self._resolve_external_ids(cr, uid, view, arch_fs) result[view.id] = arch_fs or view.arch_db return result