From e9be0bb17842a66445e5cf54fc849c4ac7ca73e5 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Mon, 3 Jun 2019 12:35:21 +0000 Subject: [PATCH] [REF] web, *: share common parts of main frontend layouts * http_routing, portal, rating, survey, website, website_survey, website_slides_survey Before this commit, the final base layout of website was a fully overridden layout of the one in portal, which was somehow a duplicated one of the login one in web, which... so lots of duplicated code. This commit is a first step towards a better organization: 1) The web app defines a frontend layout (to include base frontend assets), with a base company logo as header. 2) The portal app modifies that layout in place to include the base header, footer, ... It also uses a primary extension of it for portal pages. The survey app simply uses the above layout instead of defining its own (by primary extension to include its own assets for its own pages) Same goes for the rating app and pages. 3) The website app modifies that layout in place to include the UI assets, to add website UI, ... This allows to create frontend apps which do not depend on website, with a non duplicated layout that will be automatically adapted if website is ever installed (this therefore allows to get rid of website_survey definitely) This commit also fixes the session info system and the translation URL on the frontend side to not require to redefine the whole session_info for portal, website, ... Now the frontend session_info is defined in web and http_routing extends it to add translation informations, then website extends it again to add its own elements (not to redefine them all as before). Note: before, http_routing defined the translation route but only portal was adding it in its layout... This is an adaptation of the work that was done with commit https://github.com/odoo/odoo/commit/99821fdcf89aa66ac9561a972c6823135ebf65c0 Note 1: Many frontend but non-website apps (not only survey / rating) could probably use this too but this would be the topic of another task. Note 2: survey currently depends on http_routing but does not add itself in the list of frontend apps to translate, it probably should. Note 3: web_editor does currently not depend on http_routing but does add itself in the list of frontend apps to translate, it thus uses a function it does not really depend on... to check after its work-in- progress refactoring. task-1961045 closes odoo/odoo#33825 Signed-off-by: Quentin Smetz (qsm) --- addons/http_routing/controllers/main.py | 10 +- addons/http_routing/models/ir_http.py | 29 ++++ addons/portal/models/ir_http.py | 29 +--- addons/portal/views/portal_templates.xml | 98 ++++++-------- addons/rating/controllers/main.py | 6 +- addons/rating/views/rating_template.xml | 13 +- addons/survey/views/assets.xml | 16 --- addons/survey/views/survey_templates.xml | 49 ++----- addons/web/models/ir_http.py | 12 +- addons/web/views/webclient_templates.xml | 67 ++++++++-- addons/website/models/ir_http.py | 34 ++--- addons/website/views/website_templates.xml | 125 ++++++++---------- addons/website_slides_survey/__manifest__.py | 2 +- addons/website_survey/__init__.py | 2 - addons/website_survey/__manifest__.py | 21 --- .../views/website_survey_templates.xml | 18 --- 16 files changed, 218 insertions(+), 313 deletions(-) delete mode 100644 addons/website_survey/__init__.py delete mode 100644 addons/website_survey/__manifest__.py delete mode 100644 addons/website_survey/views/website_survey_templates.xml diff --git a/addons/http_routing/controllers/main.py b/addons/http_routing/controllers/main.py index 2a8a149b17d..dbc22d81f34 100644 --- a/addons/http_routing/controllers/main.py +++ b/addons/http_routing/controllers/main.py @@ -1,23 +1,17 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -import odoo - from odoo import http from odoo.http import request -from odoo.osv import expression from odoo.addons.web.controllers.main import WebClient, Home + class Routing(Home): @http.route('/website/translations/', type='http', auth="public", website=True) def get_website_translations(self, unique, lang, mods=None): - Modules = request.env['ir.module.module'].sudo() IrHttp = request.env['ir.http'].sudo() - domain = IrHttp._get_translation_frontend_modules_domain() - modules = Modules.search( - expression.AND([domain, [('state', '=', 'installed')]]) - ).mapped('name') + modules = IrHttp.get_translation_frontend_modules() if mods: modules += mods return WebClient().translations(unique, mods=','.join(modules), lang=lang) diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index 0e2ecc1e33f..8208cc5527d 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +import hashlib +import json import logging import os import re @@ -16,6 +18,7 @@ import odoo from odoo import api, models from odoo.addons.base.models.ir_http import RequestUID, ModelConverter from odoo.http import request +from odoo.osv import expression from odoo.tools import config, ustr, pycompat from ..geoipresolver import GeoIPResolver @@ -236,6 +239,32 @@ class IrHttp(models.AbstractModel): return request.env['res.lang'].search([('code', '=', lang_code)], limit=1) return request.env['res.lang'].search([], limit=1) + @api.model + def get_frontend_session_info(self): + session_info = super(IrHttp, self).get_frontend_session_info() + + IrHttpModel = request.env['ir.http'].sudo() + modules = IrHttpModel.get_translation_frontend_modules() + user_context = request.session.get_context() if request.session.uid else {} + lang = user_context.get('lang') + translations, _ = request.env['ir.translation'].get_translations_for_webclient(modules, lang) + + session_info.update({ + 'translationURL': '/website/translations/', + 'cache_hashes': { + 'translations': hashlib.sha1(json.dumps(translations, sort_keys=True).encode()).hexdigest(), + }, + }) + return session_info + + @api.model + def get_translation_frontend_modules(self): + Modules = request.env['ir.module.module'].sudo() + domain = self._get_translation_frontend_modules_domain() + return Modules.search( + expression.AND([domain, [('state', '=', 'installed')]]) + ).mapped('name') + @classmethod def _get_translation_frontend_modules_domain(cls): """ Return a domain to list the domain adding web-translations and diff --git a/addons/portal/models/ir_http.py b/addons/portal/models/ir_http.py index 1345d51a655..2c654c73986 100644 --- a/addons/portal/models/ir_http.py +++ b/addons/portal/models/ir_http.py @@ -1,11 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -import hashlib -import json -from odoo import api, fields, models +from odoo import models from odoo.osv import expression -from odoo.http import request class IrHttp(models.AbstractModel): @@ -15,27 +12,3 @@ class IrHttp(models.AbstractModel): def _get_translation_frontend_modules_domain(cls): domain = super(IrHttp, cls)._get_translation_frontend_modules_domain() return expression.OR([domain, [('name', '=', 'portal')]]) - - @api.model - def get_portal_session_info(self): - # see http_routing/main.py - Modules = request.env['ir.module.module'].sudo() - IrHttp = request.env['ir.http'].sudo() - domain = IrHttp._get_translation_frontend_modules_domain() - modules = Modules.search( - expression.AND([domain, [('state', '=', 'installed')]]) - ).mapped('name') - user_context = request.session.get_context() if request.session.uid else {} - lang = user_context.get('lang') - translations, _ = request.env['ir.translation'].get_translations_for_webclient(modules, lang) - return { - 'is_admin': self.env.user._is_admin(), - 'is_system': self.env.user._is_system(), - 'is_website_user': self.env.user._is_public(), - 'user_id': self.env.user.id, - 'is_frontend': True, - 'translationURL': '/website/translations', - 'cache_hashes': { - 'translations': hashlib.sha1(json.dumps(translations, sort_keys=True).encode()).hexdigest(), - }, - } diff --git a/addons/portal/views/portal_templates.xml b/addons/portal/views/portal_templates.xml index 8562d316272..2f1a4859888 100644 --- a/addons/portal/views/portal_templates.xml +++ b/addons/portal/views/portal_templates.xml @@ -1,67 +1,45 @@ -