From 85c466611a0c213d1ed2c6675fec24a7fb61157b Mon Sep 17 00:00:00 2001 From: Xavier Morel <xmo@openerp.com> Date: Tue, 27 May 2014 11:31:44 +0200 Subject: [PATCH] [IMP] don't pointlessly recreate view_obj every time _views_get is called, better use of pool & data APIs --- addons/website/models/ir_ui_view.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py index 26ca5eebfc6b..1c5736c0cffc 100644 --- a/addons/website/models/ir_ui_view.py +++ b/addons/website/models/ir_ui_view.py @@ -24,23 +24,26 @@ class view(osv.osv): 'page': False, } + + def _view_obj(self, cr, uid, view_id, context=None): + if isinstance(view_id, basestring): + return self.pool['ir.model.data'].xmlid_to_object( + cr, uid, view_id, raise_if_not_found=True, context=context + ) + elif isinstance(view_id, (int, long)): + return self.browse(cr, uid, view_id, context=context) + + # assume it's already a view object (WTF?) + return view_id + # Returns all views (called and inherited) related to a view # Used by translation mechanism, SEO and optional templates - def _views_get(self, cr, uid, view, options=True, context=None, root=True): + def _views_get(self, cr, uid, view_id, options=True, context=None, root=True): if not context: context = {} - def view_obj(view): - if isinstance(view, basestring): - mod_obj = self.pool.get("ir.model.data") - m, n = view.split('.') - view = mod_obj.get_object(cr, uid, m, n, context=context) - elif isinstance(view, (int, long)): - view = self.pool.get("ir.ui.view").browse(cr, uid, view, context=context) - return view - try: - view = view_obj(view) + view = self._view_obj(cr, uid, view_id, context=context) except ValueError: # Shall we log that ? return [] @@ -53,7 +56,7 @@ class view(osv.osv): node = etree.fromstring(view.arch) for child in node.xpath("//t[@t-call]"): try: - call_view = view_obj(child.get('t-call')) + call_view = self._view_obj(cr, uid, child.get('t-call'), context=context) except ValueError: continue if call_view not in result: -- GitLab