From bae7e32e4bd484212c891aa39eab564073ca03ae Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Fri, 23 Mar 2018 11:19:26 +0100 Subject: [PATCH] [FIX] website: see versionning changes Website Versioning module (website_version) is applied when displaying views by interfering when doing the "render the view of this `key`" and showing the view with the same `key` but of the currently displayed version. The website.page model when directly rendering a page would directly specify its `id`, thus website version was bypassed and just the master page was displayed. With this commit website.page has a "get_view_identifier" that can be overrided in website_version and has the same previous behavior otherwise. This changeset also solves a conflict (`website().get_current_website` also modify `request.context`) when modifying the context which also disabled versions. opw-1824957 closes #23847 --- addons/website/models/ir_http.py | 10 +++++----- addons/website/models/website.py | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py index c87d7226893..f25a38ca456 100644 --- a/addons/website/models/ir_http.py +++ b/addons/website/models/ir_http.py @@ -70,15 +70,15 @@ class Http(models.AbstractModel): @classmethod def _add_dispatch_parameters(cls, func): - context = dict(request.context) - if not context.get('tz'): + context = {} + if not request.context.get('tz'): context['tz'] = request.session.get('geoip', {}).get('time_zone') request.website = request.env['website'].get_current_website() # can use `request.env` since auth methods are called context['website_id'] = request.website.id - # bind modified context - request.context = context + # modify bound context + request.context = dict(request.context, **context) super(Http, cls)._add_dispatch_parameters(func) @@ -116,7 +116,7 @@ class Http(models.AbstractModel): mypage = pages[0] if pages else False _, ext = os.path.splitext(req_page) if mypage: - return request.render(mypage.view_id.id, { + return request.render(mypage.get_view_identifier(), { # 'path': req_page[1:], 'deletable': True, 'main_object': mypage, diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 153d8578a3c..35038877749 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -658,6 +658,11 @@ class Page(models.Model): item = self.search_read(domain, fields=['id', 'name', 'url', 'website_published', 'website_indexed', 'date_publish', 'menu_ids', 'is_homepage'], limit=1) return item + @api.multi + def get_view_identifier(self): + """ Get identifier of this page view that may be used to render it """ + return self.view_id.id + @api.model def save_page_info(self, website_id, data): website = self.env['website'].browse(website_id)