[IMP] orm: improved @version spec validation for inherited views
bzr revid: odo@openerp.com-20120611173132-3ioptod9jwxttopc
This commit is contained in:
parent
2126f83a35
commit
31b9bee006
|
@ -1977,6 +1977,7 @@ class BaseModel(object):
|
||||||
|
|
||||||
def raise_view_error(error_msg, child_view_id):
|
def raise_view_error(error_msg, child_view_id):
|
||||||
view, child_view = self.pool.get('ir.ui.view').browse(cr, user, [view_id, child_view_id], context)
|
view, child_view = self.pool.get('ir.ui.view').browse(cr, user, [view_id, child_view_id], context)
|
||||||
|
error_msg = error_msg % {'parent_xml_id': view.xml_id}
|
||||||
raise AttributeError("View definition error for inherited view '%s' on model '%s': %s"
|
raise AttributeError("View definition error for inherited view '%s' on model '%s': %s"
|
||||||
% (child_view.xml_id, self._name, error_msg))
|
% (child_view.xml_id, self._name, error_msg))
|
||||||
|
|
||||||
|
@ -2005,16 +2006,18 @@ class BaseModel(object):
|
||||||
if node.get('name') == spec.get('name'):
|
if node.get('name') == spec.get('name'):
|
||||||
return node
|
return node
|
||||||
return None
|
return None
|
||||||
else:
|
|
||||||
for node in source.getiterator(spec.tag):
|
for node in source.getiterator(spec.tag):
|
||||||
good = True
|
if isinstance(node, SKIPPED_ELEMENT_TYPES):
|
||||||
for attr in spec.attrib:
|
continue
|
||||||
if attr != 'position' and (not node.get(attr) or node.get(attr) != spec.get(attr)):
|
if all(node.get(attr) == spec.get(attr) \
|
||||||
good = False
|
for attr in spec.attrib
|
||||||
break
|
if attr not in ('position','version')):
|
||||||
if good:
|
# Version spec should match parent's root element's version
|
||||||
return node
|
if spec.get('version') and spec.get('version') != source.get('version'):
|
||||||
return None
|
return None
|
||||||
|
return node
|
||||||
|
return None
|
||||||
|
|
||||||
def apply_inheritance_specs(source, specs_arch, inherit_id=None):
|
def apply_inheritance_specs(source, specs_arch, inherit_id=None):
|
||||||
""" Apply an inheriting view.
|
""" Apply an inheriting view.
|
||||||
|
@ -2080,7 +2083,11 @@ class BaseModel(object):
|
||||||
if attr != 'position'
|
if attr != 'position'
|
||||||
])
|
])
|
||||||
tag = "<%s%s>" % (spec.tag, attrs)
|
tag = "<%s%s>" % (spec.tag, attrs)
|
||||||
|
if spec.get('version') and spec.get('version') != source.get('version'):
|
||||||
|
raise_view_error("Mismatching view API version for element '%s': %r vs %r in parent view '%%(parent_xml_id)s'" % \
|
||||||
|
(tag, spec.get('version'), source.get('version')), inherit_id)
|
||||||
raise_view_error("Element '%s' not found in parent view '%%(parent_xml_id)s'" % tag, inherit_id)
|
raise_view_error("Element '%s' not found in parent view '%%(parent_xml_id)s'" % tag, inherit_id)
|
||||||
|
|
||||||
return source
|
return source
|
||||||
|
|
||||||
def apply_view_inheritance(cr, user, source, inherit_id):
|
def apply_view_inheritance(cr, user, source, inherit_id):
|
||||||
|
|
Loading…
Reference in New Issue