From ddfb9c2186193af283d245ee2d9612dc29c220be Mon Sep 17 00:00:00 2001 From: "Arthur Detroux (ard)" Date: Fri, 2 Dec 2022 13:41:06 +0000 Subject: [PATCH] [FIX] website: prevent tb when using a background video as cover Prior to this commit, when using a background video on the cover of the website_slides homepage (/slides), after saving, a traceback would occur and the video would not be displayed. Steps to reproduce: - Install website_slide - Go to /slides - Enter edit mode - Change the cover of the page by a video - Save - Traceback The reason for that is that the cover snippet used on the homepage of elearning is the root of an XPath instead of its own oe_structure. (This was changed in 16.0) [1] made it so that the style and class attributes are saved but did not save any data attributes needed for the background-video widget to work. This commit adds those data attributes. [1]: https://github.com/odoo/odoo/commit/5b252215dc375526af87c31a32256dd1a9582f02 opw-3063043 closes odoo/odoo#107577 X-original-commit: 86dc4d4349d033c95c0e04e8c173f63e5e2044ed Signed-off-by: Romain Derie (rde) --- addons/web_editor/models/ir_ui_view.py | 6 +++++- addons/website/models/ir_ui_view.py | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/models/ir_ui_view.py b/addons/web_editor/models/ir_ui_view.py index 3568123a31f..8b69d6e02ec 100644 --- a/addons/web_editor/models/ir_ui_view.py +++ b/addons/web_editor/models/ir_ui_view.py @@ -117,6 +117,10 @@ class IrUiView(models.Model): return False return all(self._are_archs_equal(arch1, arch2) for arch1, arch2 in zip(arch1, arch2)) + @api.model + def _get_allowed_root_attrs(self): + return ['style', 'class'] + def replace_arch_section(self, section_xpath, replacement, replace_tail=False): # the root of the arch section shouldn't actually be replaced as it's # not really editable itself, only the content truly is editable. @@ -132,7 +136,7 @@ class IrUiView(models.Model): root.text = replacement.text # We need to replace some attrib for styles changes on the root element - for attribute in ('style', 'class'): + for attribute in self._get_allowed_root_attrs(): if attribute in replacement.attrib: root.attrib[attribute] = replacement.attrib[attribute] diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py index 54b26d2cd57..4e803e30ff7 100644 --- a/addons/website/models/ir_ui_view.py +++ b/addons/website/models/ir_ui_view.py @@ -484,6 +484,14 @@ class View(models.Model): self = website_specific_view super(View, self).save(value, xpath=xpath) + @api.model + def _get_allowed_root_attrs(self): + # Related to these options: + # background-video, background-shapes, parallax + return super()._get_allowed_root_attrs() + [ + 'data-bg-video-src', 'data-shape', 'data-scroll-background-ratio', + ] + # -------------------------------------------------------------------------- # Snippet saving # --------------------------------------------------------------------------