From 85a19db1fe5a991e0efbd47d1eb84e66dc3f9201 Mon Sep 17 00:00:00 2001 From: Olivier Laurent Date: Mon, 21 Sep 2015 12:36:02 +0200 Subject: [PATCH] [IMP] base: use 'raise_view_error' when checking the inheritance The message used in 'valid_inheritance' was not very helpful when the inheritance validity was not passed. You only knew that some view was not OK without knowing which one. We now use the 'raise_view_error' method, which can already display all the meaningful info (view_id, parent_id, view name, ...) --- openerp/addons/base/ir/ir_ui_view.py | 32 +++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/openerp/addons/base/ir/ir_ui_view.py b/openerp/addons/base/ir/ir_ui_view.py index 41d71cd6d73..b1b2aec49a0 100644 --- a/openerp/addons/base/ir/ir_ui_view.py +++ b/openerp/addons/base/ir/ir_ui_view.py @@ -128,19 +128,6 @@ xpath_utils['hasclass'] = _hasclass TRANSLATED_ATTRS_RE = re.compile(r"@(%s)\b" % "|".join(TRANSLATED_ATTRS)) -def valid_inheritance(arch): - """ Check whether view inheritance is based on translated attribute. """ - for node in arch.xpath('//*[@position]'): - # inheritance may not use a translated attribute as selector - if node.tag == 'xpath': - match = TRANSLATED_ATTRS_RE.search(node.get('expr', '')) - if match: - raise ValidationError("View inheritance may not use attribute %r as a selector." % match.group(1)) - else: - for attr in TRANSLATED_ATTRS: - if node.get(attr): - raise ValidationError("View inheritance may not use attribute %r as a selector." % attr) - return True class view(osv.osv): _name = 'ir.ui.view' @@ -275,6 +262,22 @@ class view(osv.osv): frng.close() return self._relaxng_validator + def _valid_inheritance(self, view, arch): + """ Check whether view inheritance is based on translated attribute. """ + for node in arch.xpath('//*[@position]'): + # inheritance may not use a translated attribute as selector + if node.tag == 'xpath': + match = TRANSLATED_ATTRS_RE.search(node.get('expr', '')) + if match: + message = "View inheritance may not use attribute %r as a selector." % match.group(1) + self.raise_view_error(view._cr, view._uid, message, view.id) + else: + for attr in TRANSLATED_ATTRS: + if node.get(attr): + message = "View inheritance may not use attribute %r as a selector." % attr + self.raise_view_error(view._cr, view._uid, message, view.id) + return True + def _check_xml(self, cr, uid, ids, context=None): if context is None: context = {} @@ -284,8 +287,7 @@ class view(osv.osv): # Any exception raised below will cause a transaction rollback. for view in self.browse(cr, uid, ids, context): view_arch = etree.fromstring(encode(view.arch)) - if not valid_inheritance(view_arch): - return False + self._valid_inheritance(view, view_arch) view_def = self.read_combined(cr, uid, view.id, ['arch'], context=context) view_arch_utf8 = view_def['arch'] if view.type != 'qweb':