[IMP] website: load theme images also when module install through CLI

Themes image would not be shown correctly in the theme selection if the
`website` module was installed in CLI.
Indeed, the code supposed to load the theme images was done in the kanban view
during theme selection after installing module through apps screen.

Now, this code is encapsulated and called in post_init hook of website.
This was also needed for an improvement on `test_themes` module, see
https://github.com/odoo/design-themes/pull/195.

closes odoo/odoo#42206

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
Romain Derie
2020-01-07 16:11:52 +00:00
parent 387f199ee7
commit c86bff6a02
5 changed files with 30 additions and 24 deletions
+5
View File
@@ -20,3 +20,8 @@ def uninstall_hook(cr, registry):
('model', '=', 'res.config.settings'),
]).unlink()
cr.after('commit', partial(rem_website_id_null, cr.dbname))
def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
env['ir.module.module'].update_theme_images()
+1
View File
@@ -79,5 +79,6 @@
'static/src/xml/theme_preview.xml',
],
'application': True,
'post_init_hook': 'post_init_hook',
'uninstall_hook': 'uninstall_hook',
}
+12 -5
View File
@@ -373,16 +373,24 @@ class IrModuleModule(models.Model):
@api.model
def update_list(self):
res = super(IrModuleModule, self).update_list()
self.update_theme_images()
return res
@api.model
def update_theme_images(self):
IrAttachment = self.env['ir.attachment']
existing_urls = IrAttachment.search_read([['res_model', '=', self._name], ['type', '=', 'url']], ['url'])
existing_urls = [url_wrapped['url'] for url_wrapped in existing_urls]
for app in self.search([]):
terp = self.get_module_info(app.name)
themes = self.env['ir.module.module'].with_context(active_test=False).search([
('category_id', 'child_of', self.env.ref('base.module_category_theme').id),
], order='name')
for theme in themes:
terp = self.get_module_info(theme.name)
images = terp.get('images', [])
for image in images:
image_path = os.path.join(app.name, image)
image_path = os.path.join(theme.name, image)
if image_path not in existing_urls:
image_name = os.path.basename(image_path)
IrAttachment.create({
@@ -390,6 +398,5 @@ class IrModuleModule(models.Model):
'name': image_name,
'url': image_path,
'res_model': self._name,
'res_id': app.id,
'res_id': theme.id,
})
return res
@@ -75,7 +75,7 @@
<li class="o_mobile_preview" id="mobile-menu">
<a data-action="show-mobile-preview" href="#"><span title="Mobile preview" role="img" aria-label="Mobile preview" class="fa fa-mobile"/></a>
</li>
<li groups="website.group_multi_website" t-if="multi_website_websites">
<li groups="website.group_multi_website" t-if="multi_website_websites" id="website_switcher">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-globe d-lg-none"/>
<span class="d-none d-lg-inline-block">
+11 -18
View File
@@ -380,24 +380,6 @@
</record>
<!-- Actions to list themes with custom kanban (launched on module installation) -->
<record id="theme_install_todo_action" model="ir.actions.server">
<field name="name">Config: Choose Your Theme</field>
<field name="model_id" ref="model_ir_module_module"/>
<field name="state">code</field>
<field name="code">
model.update_list()
action = {
'type': 'ir.actions.act_url',
'url': '/web?reload#action=website.theme_install_kanban_action', # the ?reload option is there to fool the webclient into thinking it is a different location and so to force a reload
'target': 'self',
}
</field>
</record>
<record id="theme_install_todo" model="ir.actions.todo">
<field name="action_id" ref="theme_install_todo_action"/>
<field name="sequence">0</field>
</record>
<record id="theme_view_form_preview" model="ir.ui.view">
<field name="name">website.form</field>
<field name="model">ir.module.module</field>
@@ -430,6 +412,17 @@ action = {
]"/>
</record>
<record id="theme_install_act_url" model="ir.actions.act_url">
<field name="name">Website</field>
<field name="url">/web?reload#action=website.theme_install_kanban_action</field>
<field name="target">self</field>
</record>
<record id="theme_install_todo" model="ir.actions.todo">
<field name="action_id" ref="theme_install_act_url"/>
<field name="sequence">0</field>
</record>
<!-- ONBOARDING -->
<template id="onboarding_website_theme_step">
<t t-call="base.onboarding_step">