[MERGE] refactoring: view inheritance query moved to ir.ui.view, courtesy of Sebastien Beau (Akretion)
bzr revid: odo@openerp.com-20110919152434-uohc9mqr4n0b1sc8
This commit is contained in:
commit
4517dbb852
|
@ -96,6 +96,19 @@ class view(osv.osv):
|
|||
if not cr.fetchone():
|
||||
cr.execute('CREATE INDEX ir_ui_view_model_type_inherit_id ON ir_ui_view (model, type, inherit_id)')
|
||||
|
||||
def get_inheriting_views_arch(self, cr, uid, view_id, model, context=None):
|
||||
"""Retrieves the architecture of views that inherit from the given view.
|
||||
|
||||
:param int view_id: id of the view whose inheriting views should be retrieved
|
||||
:param str model: model identifier of the view's related model (for double-checking)
|
||||
:rtype: list of tuples
|
||||
:return: [(view_arch,view_id), ...]
|
||||
"""
|
||||
cr.execute("""SELECT arch, id FROM ir_ui_view WHERE inherit_id=%s AND model=%s
|
||||
ORDER BY priority""",
|
||||
(view_id, model))
|
||||
return cr.fetchall()
|
||||
|
||||
def write(self, cr, uid, ids, vals, context={}):
|
||||
if not isinstance(ids, (list, tuple)):
|
||||
ids = [ids]
|
||||
|
|
|
@ -1909,22 +1909,20 @@ class orm_template(object):
|
|||
raise_view_error("Element '%s' not found in parent view '%%(parent_xml_id)s'" % tag, inherit_id)
|
||||
return source
|
||||
|
||||
def apply_view_inheritance(source, inherit_id):
|
||||
def apply_view_inheritance(cr, user, source, inherit_id):
|
||||
""" Apply all the (directly and indirectly) inheriting views.
|
||||
|
||||
:param source: a parent architecture to modify (with parent
|
||||
modifications already applied)
|
||||
:param inherit_id: the database id of the parent view
|
||||
:param inherit_id: the database view_id of the parent view
|
||||
:return: a modified source where all the modifying architecture
|
||||
are applied
|
||||
|
||||
"""
|
||||
# get all views which inherit from (ie modify) this view
|
||||
cr.execute('select arch,id from ir_ui_view where inherit_id=%s and model=%s order by priority', (inherit_id, self._name))
|
||||
sql_inherit = cr.fetchall()
|
||||
for (inherit, id) in sql_inherit:
|
||||
source = apply_inheritance_specs(source, inherit, id)
|
||||
source = apply_view_inheritance(source, id)
|
||||
sql_inherit = self.pool.get('ir.ui.view').get_inheriting_views_arch(cr, user, inherit_id, self._name)
|
||||
for (view_arch, view_id) in sql_inherit:
|
||||
source = apply_inheritance_specs(source, view_arch, view_id)
|
||||
source = apply_view_inheritance(cr, user, source, view_id)
|
||||
return source
|
||||
|
||||
result = {'type': view_type, 'model': self._name}
|
||||
|
@ -1967,7 +1965,7 @@ class orm_template(object):
|
|||
result['view_id'] = sql_res['id']
|
||||
|
||||
source = etree.fromstring(encode(sql_res['arch']))
|
||||
result['arch'] = apply_view_inheritance(source, result['view_id'])
|
||||
result['arch'] = apply_view_inheritance(cr, user, source, result['view_id'])
|
||||
|
||||
result['name'] = sql_res['name']
|
||||
result['field_parent'] = sql_res['field_parent'] or False
|
||||
|
|
Loading…
Reference in New Issue