[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.
This commit is contained in:
Jeremy Kersten
2015-09-25 15:14:50 +02:00
parent 5f0d90d807
commit f411fef90c
+6 -13
View File
@@ -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<prefix>[^%])%\((?P<xmlid>.*?)\)[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