From 928eeca714a161f6bc03343e4dc8af9b050b9841 Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Mon, 28 Aug 2023 13:50:24 +0200 Subject: [PATCH] [IMP] website: use dedicated templates in configurator This commit adapts the configurator so that the pages it generates are composed of the primary templates generated from the manifest by the previous commit. task-3381714 Part-of: odoo/odoo#126719 --- addons/website/models/ir_module_module.py | 2 ++ addons/website/models/website.py | 5 +++-- addons/website/tests/test_views.py | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/website/models/ir_module_module.py b/addons/website/models/ir_module_module.py index a4c2a89b542..e39eabbb884 100644 --- a/addons/website/models/ir_module_module.py +++ b/addons/website/models/ir_module_module.py @@ -231,6 +231,7 @@ class IrModuleModule(models.Model): for module in self: _logger.info('Load theme %s for website %s from template.' % (module.mapped('name'), website.id)) + module._generate_primary_snippet_templates() for model_name in self._theme_model_names: module._update_records(model_name, website) @@ -442,6 +443,7 @@ class IrModuleModule(models.Model): ], order='name') for theme in themes: + theme._generate_primary_snippet_templates() terp = self.get_module_info(theme.name) images = terp.get('images', []) for image in images: diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 791b2d8798e..f64bd14803b 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -427,6 +427,7 @@ class Website(models.Model): website = self.get_current_website() theme_name = kwargs['theme_name'] theme = self.env['ir.module.module'].search([('name', '=', theme_name)]) + theme._generate_primary_snippet_templates() redirect_url = theme.button_choose_theme() # Force to refresh env after install of module @@ -614,7 +615,7 @@ class Website(models.Model): for page_code in requested_pages - {'privacy_policy'}: snippet_list = snippet_lists.get(page_code, []) for snippet in snippet_list: - render, placeholders = _render_snippet(f'website.{snippet}') + render, placeholders = _render_snippet(f'website.configurator_{page_code}_{snippet}') for placeholder in placeholders: generated_content[placeholder] = '' try: @@ -642,7 +643,7 @@ class Website(models.Model): nb_snippets = len(snippet_list) for i, snippet in enumerate(snippet_list, start=1): try: - render, placeholders = _render_snippet(f'website.{snippet}') + render, placeholders = _render_snippet(f'website.configurator_{page_code}_{snippet}') # Fill rendered block with AI text render = xml_translate( diff --git a/addons/website/tests/test_views.py b/addons/website/tests/test_views.py index 18768afd9bf..393001f1b3a 100644 --- a/addons/website/tests/test_views.py +++ b/addons/website/tests/test_views.py @@ -8,6 +8,7 @@ from itertools import zip_longest from lxml import etree as ET, html from lxml.html import builder as h +from odoo.modules.module import _DEFAULT_MANIFEST, get_manifest from odoo.tests import common, HttpCase, tagged @@ -1510,6 +1511,9 @@ class TestThemeViews(common.TransactionCase): # 2. Simulate a theme install with a child view of `main_view` test_theme_module = self.env['ir.module.module'].create({'name': 'test_theme'}) + # Themes are required to have a valid manifest, including a `new_page_templates` property. + # This theme is created in python and therefore has no manifest. + get_manifest('test_theme').update(_DEFAULT_MANIFEST) self.env['ir.model.data'].create({ 'module': 'base', 'name': 'module_test_theme_module',