Skip to content
Snippets Groups Projects
Commit f32992de authored by qsm-odoo's avatar qsm-odoo
Browse files

[FIX] website_blog: fix link on the top banner of /blog


Before this commit, following these steps:
- Go to /blog
- Activate the option Customize > Top banner - Name / Latest Post
- Disable the option Customize > Full Width Cover

The URL to which we are redirected when we click on the blog of the
post presented at the top of the page leads to an error.

Indeed the URL of that link is something like "/blog?blog=blog.blog(2,)"
because of the template wrongly using the 'blog_url' QueryURL which is
defined in the case where we are rendering a blog page where no specific
blog is selected. We define that as `QueryURL('/blog', ['tag'], ...)`
but then parts of the template used it like this: `blog_url(blog=X)`
thus generating an URL like "/blog?blog=blog.blog(2,)". Adding "blog" to
the list of params would not be right as would create "/blog/blog/2"
which is still wrong as we want "/blog/2". And of course the "/blog"
prefix in the QueryURL definition is needed in case we only specify a
tag via `blog_url(tag=X)` (we expect /blog/tag/X). Patching QueryURL or
making blog_url a custom function instead of a QueryURL instance could
be a solution but it was judged not stable enough. We'll do that in
master. Here we only support "/blog?blog=blog.blog(2,)" URLs.

Note that many parts of those templates do not use the `blog_url`
function and simply build the URL by hand, which is why the bug only
occurred for a very specific set of blog options.

opw-2882492

Part-of: odoo/odoo#93680
Co-authored-by: default avatarGuillaume (gdi) <gdi@odoo.com>
parent b89b70cc
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import json
import re
import werkzeug
import itertools
import pytz
......@@ -149,6 +149,25 @@ class WebsiteBlog(http.Controller):
], type='http', auth="public", website=True)
def blog(self, blog=None, tag=None, page=1, **opt):
Blog = request.env['blog.blog']
# TODO adapt in master. This is a fix for templates wrongly using the
# 'blog_url' QueryURL which is defined below. Indeed, in the case where
# we are rendering a blog page where no specific blog is selected we
# define(d) that as `QueryURL('/blog', ['tag'], ...)` but then some
# parts of the template used it like this: `blog_url(blog=XXX)` thus
# generating an URL like "/blog?blog=blog.blog(2,)". Adding "blog" to
# the list of params would not be right as would create "/blog/blog/2"
# which is still wrong as we want "/blog/2". And of course the "/blog"
# prefix in the QueryURL definition is needed in case we only specify a
# tag via `blog_url(tab=X)` (we expect /blog/tag/X). Patching QueryURL
# or making blog_url a custom function instead of a QueryURL instance
# could be a solution but it was judged not stable enough. We'll do that
# in master. Here we only support "/blog?blog=blog.blog(2,)" URLs.
if isinstance(blog, str):
blog = Blog.browse(int(re.search(r'\d+', blog)[0]))
if not blog.exists():
raise werkzeug.exceptions.NotFound()
if blog and not blog.can_access_from_current_website():
raise werkzeug.exceptions.NotFound()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment