From b7fef8d2d303d0157582602b3f5791a23114c364 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 14 Aug 2013 12:18:57 +0200 Subject: [PATCH] [FIX] website: infinite loop when they are a recursive template bzr revid: chm@openerp.com-20130814101857-nqyx0skr6m84kjfw --- addons/website/view.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/addons/website/view.py b/addons/website/view.py index fb548651c5f..9d990bdb388 100644 --- a/addons/website/view.py +++ b/addons/website/view.py @@ -13,14 +13,23 @@ class view(osv.osv): # 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={}, root=True): - if type(view) in (str, unicode): - mod_obj = self.pool.get("ir.model.data") - m, n = view.split('.') - _, view = mod_obj.get_object_reference(cr, uid, m, n) - if type(view) == int: - view_obj = self.pool.get("ir.ui.view") - view = view_obj.browse(cr, uid, view, context=context) + def _views_get(self, cr, uid, view, options=True, context=None, root=True, stack_result=None): + if not context: + context = {} + if not stack_result: + stack_result = [] + + def view_obj(view): + if type(view) in (str, unicode): + mod_obj = self.pool.get("ir.model.data") + m, n = view.split('.') + _, view = mod_obj.get_object_reference(cr, uid, m, n) + if type(view) == int: + view_obj = self.pool.get("ir.ui.view") + view = view_obj.browse(cr, uid, view, context=context) + return view + view = view_obj(view) + while root and view.inherit_id: view = view.inherit_id @@ -29,8 +38,10 @@ class view(osv.osv): if options: todo += filter(lambda x: not x.inherit_id, view.inherited_option_ids) for child_view in todo: - result += self._views_get(cr, uid, child_view, options=options, context=context, root=False) + result += self._views_get(cr, uid, child_view, options=options, context=context, root=False, stack_result=result) node = etree.fromstring(view.arch) for child in node.xpath("//t[@t-call]"): - result += self._views_get(cr, uid, child.get('t-call'), options=options, context=context) + call_view = view_obj(child.get('t-call')) + if call_view not in stack_result: + result += self._views_get(cr, uid, call_view, options=options, context=context, stack_result=result) return result