[REF] refactor code in order to add the possibility to overwrite the way to inherit the view

bzr revid: sebastien.beau@akretion.com.br-20110918235947-5k6bxg2fbshhtrsd
This commit is contained in:
sebastien beau 2011-09-19 01:59:47 +02:00
parent cc2df187e7
commit 043f50ba12
2 changed files with 18 additions and 6 deletions

View File

@ -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_inherit_views(self, cr, uid, id, model, context=None):
"""
Get all views which inherit from (ie modify) this view
:param cr: database cursor
:param user: current user id
:param id: id of the view
:return: list of tuple which contain of the view arch and the id
"""
cr.execute('select arch,id from ir_ui_view where inherit_id=%s and model=%s order by priority', (id, model))
return cr.fetchall()
def write(self, cr, uid, ids, vals, context={}):
if not isinstance(ids, (list, tuple)):
ids = [ids]

View File

@ -1900,7 +1900,7 @@ 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
@ -1910,12 +1910,11 @@ class orm_template(object):
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()
sql_inherit = self.pool.get('ir.ui.view').get_inherit_views(cr, user, inherit_id, self._name)
for (inherit, id) in sql_inherit:
source = apply_inheritance_specs(source, inherit, id)
source = apply_view_inheritance(source, id)
source = apply_view_inheritance(cr, user, source, id)
return source
result = {'type': view_type, 'model': self._name}
@ -1958,7 +1957,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