diff options
| author | qsm-odoo <qsm@odoo.com> | 2019-06-03 12:35:21 +0000 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2019-06-03 20:09:26 +0000 |
| commit | e9be0bb17842a66445e5cf54fc849c4ac7ca73e5 (patch) | |
| tree | 56e6f86730ff0b64a07f2bb694abe3ac78e12173 /addons/http_routing | |
| parent | 8e30349fd1f2baffd47e50106eddbd1c59979aaf (diff) | |
[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) <qsm@odoo.com>
Diffstat (limited to 'addons/http_routing')
| -rw-r--r-- | addons/http_routing/controllers/main.py | 10 | ||||
| -rw-r--r-- | addons/http_routing/models/ir_http.py | 29 |
2 files changed, 31 insertions, 8 deletions
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/<string:unique>', 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 |
