[ADD] theme 14.0

This commit is contained in:
Jeremy Kersten
2021-05-10 15:45:35 +02:00
commit cb1e3be3f8
2309 changed files with 55585 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
from odoo import api, SUPERUSER_ID
def post_init_hook(cr, registry):
''' Create a new website for each theme and install the theme on it. '''
env = api.Environment(cr, SUPERUSER_ID, {})
IrModule = env['ir.module.module']
themes = IrModule.search([
('category_id', 'child_of', env.ref('base.module_category_theme').id),
], order='name')
exclude_list = ['_common', '_blog', '_sale']
themes = themes.filtered(lambda t: not any([ex for ex in exclude_list if ex in t.name]))
assert len(themes) == len(env.ref('base.module_test_themes').dependencies_id)
xmlids = []
for theme in themes:
website = env['website'].create({
'name': theme.display_name,
'theme_id': theme.id,
})
xmlids.append({
'xml_id': 'test_themes.%s' % theme.display_name.replace(' ', '_'),
'record': website,
'noupdate': True, # Avoid unlink on -u
})
theme._theme_get_stream_themes()._theme_load(website)
env['ir.model.data']._update_xmlids(xmlids)
+49
View File
@@ -0,0 +1,49 @@
{
'name': 'Themes Testing Module',
'version': '1.0',
'category': 'Hidden',
'sequence': 9877,
'summary': 'Create a new website for each Odoo theme for an easy preview.',
'description': """This module will help you to quickly test all the Odoo
themes without having to switch from one theme to another on your website.
It will simply create a new website for each Odoo theme and install every
theme on one website.""",
'depends': [
# CE themes
'theme_default',
# design-themes themes
'theme_anelusia',
'theme_artists',
'theme_avantgarde',
'theme_beauty',
'theme_bewise',
'theme_bistro',
'theme_bookstore',
'theme_clean',
'theme_cobalt',
'theme_enark',
'theme_graphene',
'theme_kea',
'theme_kiddo',
'theme_loftspace',
'theme_monglia',
'theme_nano',
'theme_notes',
'theme_odoo_experts',
'theme_orchid',
'theme_paptic',
'theme_real_estate',
'theme_treehouse',
'theme_vehicle',
'theme_yes',
'theme_zap',
],
'data': [
'views/assets.xml',
'views/website_navbar_templates.xml',
],
'installable': True,
'application': False,
'post_init_hook': 'post_init_hook',
}
+6
View File
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import ir_http
from . import ir_ui_view
from . import website
+18
View File
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, tools
from odoo.http import request
class Http(models.AbstractModel):
_inherit = 'ir.http'
@classmethod
def _add_dispatch_parameters(cls, func):
# Allow public user to use `fw` query string in test mode to ease tests
force_website_id = request.httprequest.args.get('fw')
if (request.registry.in_test_mode() or tools.config.options['test_enable']) and force_website_id:
request.env['website']._force_website(force_website_id)
super(Http, cls)._add_dispatch_parameters(func)
+28
View File
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models
from odoo.http import request
class View(models.Model):
_name = "ir.ui.view"
_inherit = "ir.ui.view"
@api.model
def _prepare_qcontext(self):
qcontext = super(View, self)._prepare_qcontext()
if request and getattr(request, 'is_frontend', False) and 'multi_website_websites' in qcontext:
Website = self.env['website']
websites_themes = Website.get_test_themes_websites()
for multi_website_website in qcontext['multi_website_websites']:
website_id = multi_website_website['website_id']
theme_img = None
if website_id in websites_themes.ids:
# prefetched by get_test_themes_websites
website = Website.browse(website_id)
if website.theme_id.sudo().image_ids:
theme_img = "<img src='/web/image/%s' width='150'/>" % website.theme_id.sudo().image_ids[0].id
multi_website_website['theme_img'] = theme_img
return qcontext
+24
View File
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
class Website(models.Model):
_inherit = 'website'
def get_test_themes_websites(self):
website_imd_ids = self.env['ir.model.data'].sudo().search([
('module', '=', 'test_themes'),
('model', '=', 'website'),
])
return self.browse(website_imd_ids.mapped('res_id'))
def unlink(self):
websites_themes = self.get_test_themes_websites()
if self in websites_themes:
# Bypass foreign key constraint
website_domain = [('website_id', '=', self.id)]
self.env['ir.ui.view'].with_context(active_test=False, _force_unlink=True).search(website_domain).unlink()
self.env['ir.attachment'].with_context(active_test=False).search(website_domain).unlink()
return super().unlink()
+26
View File
@@ -0,0 +1,26 @@
odoo.define('test_themes.website_selector', function (require) {
'use strict';
const websiteNavbarData = require('website.navbar');
const TestThemesWebsiteSelector = websiteNavbarData.WebsiteNavbarActionWidget.extend({
/**
* @override
*/
start: function () {
this.$('.js_multi_website_switch[data-toggle]').tooltip({
html: true,
placement: 'left',
delay: {show: 100, hide: 0},
});
return this._super(...arguments);
},
});
websiteNavbarData.websiteNavbarRegistry.add(TestThemesWebsiteSelector, '#website_switcher');
return {
TestThemesWebsiteSelector: TestThemesWebsiteSelector,
};
});
+4
View File
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_crawl
+28
View File
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import HttpCase, tagged
@tagged('post_install', '-at_install')
class Crawler(HttpCase):
def test_01_crawl_every_themes(self):
""" Crawl every website (and so every themes) to ensure all themes can
be rendered and do not crash.
"""
Website = self.env['website']
websites_themes = Website.get_test_themes_websites()
assert len(websites_themes) == len(self.env.ref('base.module_test_themes').dependencies_id)
def test_crawling():
for website in websites_themes.filtered(lambda w: w.theme_id.name != 'theme_default'):
r = self.url_open('/?fw=%s&debug=assets' % website.id)
self.assertEqual(r.status_code, 200, "Ensure rendering went fine as public user")
self.assertTrue('/%s/static/src' % website.theme_id.name in r.text, "Ensure rendering went fine as public user")
# 1. Test as public user
test_crawling()
# 2. Test as admin
self.authenticate('admin', 'admin')
test_crawling()
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_frontend" inherit_id="website.assets_frontend" name="Website Assets">
<xpath expr="//script[last()]" position="after">
<script type="text/javascript" src="/test_themes/static/src/js/navbar.js"/>
</xpath>
</template>
</odoo>
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="user_navbar" inherit_id="website.user_navbar" name="User Navbar Themes">
<xpath expr="//a[hasclass('js_multi_website_switch')]" position="attributes">
<attribute name="t-att-title">multi_website_website['theme_img']</attribute>
<attribute name="data-toggle">tooltip</attribute>
</xpath>
</template>
</odoo>