[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
This commit is contained in:
Nicolas Lempereur
2018-03-26 10:53:23 +02:00
parent cafc6c3ae0
commit bae7e32e4b
2 changed files with 10 additions and 5 deletions
+5 -5
View File
@@ -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,
+5
View File
@@ -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)