From 4469b36f7705d3afeea1e212ba3dbbf487aac8ec Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 17 Dec 2013 12:20:34 +0100 Subject: [PATCH] [FIX] change view section saving: only save view section *content* Before, would save view section itself (including root element). But branding distribution (and thus editability) are set on the last programmatic root, thus the root element may well be generated e.g. will define the span itself as editable. Saving this would remove the programmatic content on the node, and thus break the view section altogether. Fix the issue by only saving the root's content in the previous root. bzr revid: xmo@openerp.com-20131217112034-nbxbg919cffv4w51 --- addons/website/models/ir_ui_view.py | 22 ++++++++++++++-------- addons/website/tests/test_views.py | 11 +++++++++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py index ad95a6b9ff7..b935d6e3465 100644 --- a/addons/website/models/ir_ui_view.py +++ b/addons/website/models/ir_ui_view.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import copy from urlparse import urlparse from lxml import etree, html @@ -84,19 +85,24 @@ class view(osv.osv): return out def replace_arch_section(self, cr, uid, view_id, section_xpath, replacement, context=None): - # remove branding from replacement section - for att in ir.ir_ui_view.MOVABLE_BRANDING: - replacement.attrib.pop(att, None) + # the root of the arch section shouldn't actually be replaced as it's + # not really editable itself, only the content truly is editable. + [view] = self.browse(cr, uid, [view_id], context=context) + arch = etree.fromstring(view.arch.encode('utf-8')) + # => get the replacement root if not section_xpath: - # replace all of the arch, not just a fragment - arch = replacement + root = arch else: - arch = etree.fromstring(self.browse(cr, uid, view_id, context=context).arch.encode('utf-8')) # ensure there's only one match - [previous_section] = arch.xpath(section_xpath) + [root] = arch.xpath(section_xpath) - previous_section.getparent().replace(previous_section, replacement) + root.text = replacement.text + root.tail = replacement.tail + # replace all children + del root[:] + for child in replacement: + root.append(copy.deepcopy(child)) return arch diff --git a/addons/website/tests/test_views.py b/addons/website/tests/test_views.py index 812981cd706..8041a7e5f1c 100644 --- a/addons/website/tests/test_views.py +++ b/addons/website/tests/test_views.py @@ -92,10 +92,17 @@ class TestViewSaving(common.TransactionCase): self.eq(View.to_field_ref(self.cr, self.uid, embedded, context=None), h.SPAN({'t-field': 'bob', 'class': 'foo bar', 'id': 'whop'})) - def test_replace_arch(self): replacement = h.P("Wheee") + result = self.registry('ir.ui.view').replace_arch_section( + self.cr, self.uid, self.view_id, None, replacement) + + self.eq(result, h.DIV("Wheee")) + + def test_replace_arch_2(self): + replacement = h.DIV(h.P("Wheee")) + result = self.registry('ir.ui.view').replace_arch_section( self.cr, self.uid, self.view_id, None, replacement) @@ -110,7 +117,7 @@ class TestViewSaving(common.TransactionCase): self.eq(result, h.DIV( h.DIV( - h.H1("I am the greatest title alive!"), + h.H3("I am the greatest title alive!"), h.UL( h.LI("Item 1"), h.LI("Item 2"),