由于加载页面首先显示 load_views,因此分析此函数,看能做什么文章
@api.model
def load_views(self, views, options=None):
""" Returns the fields_views of given views, along with the fields of
the current model, and optionally its filters for the given action.
:param views: list of [view_id, view_type]
:param options['toolbar']: True to include contextual actions when loading fields_views
:param options['load_filters']: True to return the model's filters
:param options['action_id']: id of the action to get the filters
:return: dictionary with fields_views, fields and optionally filters
"""
options = options or {}
result = {}
toolbar = options.get('toolbar')
result['fields_views'] = {
v_type: self.fields_view_get(v_id, v_type if v_type != 'list' else 'tree',
toolbar=toolbar if v_type != 'search' else False)
for [v_id, v_type] in views
}
result['fields'] = self.fields_get()
if options.get('load_filters'):
result['filters'] = self.env['ir.filters'].get_filters(self._name, options.get('action_id'))
return result
先分析主要函数 fields_view_get
通过调试,先看整体,返回 result
{
'type':'form',
'name':'zhy.sale.form'
'arch':'数据库中 xml内容',
'model':zhy.sale,
'fields': '根据权限等可以显示的字段'}
可以看出 此函数主要作用 根据view_id 。从view 表得到 view model 的 详细信息
只看主要信息
xarch, xfields = View.postprocess_and_fields(self._name, etree.fromstring(result['arch']), view_id)
result['arch'] = xarch
result['fields'] = xfields
xarch 就是 数据库里面的 内容,xfields 是 modle 的 所有字段
进入VIEW 的函数,可以看到重要的信息
#递归处理字段
fields_def = self.postprocess(model, node, view_id, False, fields)
self._postprocess_access_rights(model, node)
return arch, fields
递归处理 权限和字段。下一篇分析 view 的 postprocess (xml->modle )的函数