From 953a693df1284f2292237e3479a210ba28e6f9bf Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Wed, 27 Sep 2017 20:26:25 +0200 Subject: [PATCH] [FIX] website, http_routing: fix translate on website.page Before this commit: website.page won't be rendered as translated items since it is not going though a controller (route) enabling multilang. Website.page were not considered as multilang items and no lang prefix were applied on link. Now: website.page will correcly handling translation. In case of one route doesn't match a controller, it is now by default a route of type multilang. Add a new field auto_redirect_lang on website model to allow to deactive the autoredirect of the lang optionnaly. The code will arrive after more tests. --- addons/http_routing/models/ir_http.py | 6 ++++-- addons/website/models/website.py | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index b288718ba7c..c95d86509fd 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -170,7 +170,9 @@ def is_multilang_url(local_url, langs=None): func = router.match(path, method='POST', query_args=query_string)[0] return (func.routing.get('website', False) and func.routing.get('multilang', func.routing['type'] == 'http')) - except Exception: + except werkzeug.exceptions.NotFound: + return True + except Exception as e: return False @@ -331,7 +333,7 @@ class IrHttp(models.AbstractModel): request.is_frontend_multilang = ( request.is_frontend and - func and func.routing.get('multilang', func.routing['type'] == 'http') + (not func or (func and func.routing.get('multilang', func.routing['type'] == 'http'))) ) cls._geoip_setup_resolver() diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 797825c9131..5ce52c0516c 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -50,6 +50,7 @@ class Website(models.Model): language_ids = fields.Many2many('res.lang', 'website_lang_rel', 'website_id', 'lang_id', 'Languages', default=_active_languages) default_lang_id = fields.Many2one('res.lang', string="Default Language", default=_default_language, required=True) default_lang_code = fields.Char(related='default_lang_id.code', string="Default language code", store=True) + auto_redirect_lang = fields.Boolean('Autoredirect Language', default=True, help="Should users be redirected to their browser's language") social_twitter = fields.Char(related="company_id.social_twitter") social_facebook = fields.Char(related="company_id.social_facebook")