Skip to content

Commit

Permalink
[IMP] website: use dedicated templates in configurator
Browse files Browse the repository at this point in the history
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: #126719
  • Loading branch information
bso-odoo authored and rdeodoo committed Oct 14, 2023
1 parent a2f8e18 commit 928eeca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions addons/website/models/ir_module_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def _theme_load(self, website):
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)

Expand Down Expand Up @@ -442,6 +443,7 @@ def update_theme_images(self):
], 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:
Expand Down
5 changes: 3 additions & 2 deletions addons/website/models/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ def configurator_apply(self, **kwargs):
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
Expand Down Expand Up @@ -614,7 +615,7 @@ def _render_snippet(key):
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:
Expand Down Expand Up @@ -642,7 +643,7 @@ def _render_snippet(key):
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(
Expand Down
4 changes: 4 additions & 0 deletions addons/website/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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


Expand Down Expand Up @@ -1510,6 +1511,9 @@ def test_inherit_specific(self):

# 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',
Expand Down

0 comments on commit 928eeca

Please sign in to comment.