[FIX] website_blog: prevent params to be lost when only one blog

With DB having only one blog (most common case, but we are used to test
it with demo data where we have two), the query params are lost when
accessing the blog controller without passing a blog.

Eg, `/blog?search=hubble` will redirect to `/blog/travel-1`

This is because the business code is doing an early redirect if we
access the `/blog` URL without a blog post passed to it to redirect to
that blog post URL directly (since there is only one), but that redirect
is not passing the query parameters.

The main impacted params are `state`, `order` and `search` but it's the
same for all others.

Step to reproduce (in later version):
- Be sure to only have one blog
- Drag & drop the search snippet in the homepage or anywhere
- Make it search on blog only (through the snippet option)

Type anything, it will not work and won't do the search. It will just
redirect to the blog page.

closes odoo/odoo#114107

X-original-commit: 41c27fd4912fb9f50ce5f31fff7c17c77b8530f7
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
Romain Derie
2023-03-02 16:01:17 +01:00
parent 76d339a266
commit e7b0ee3012
+2 -1
View File
@@ -196,7 +196,8 @@ class WebsiteBlog(http.Controller):
blogs = tools.lazy(lambda: Blog.search(request.website.website_domain(), order="create_date asc, id asc"))
if not blog and len(blogs) == 1:
return request.redirect('/blog/%s' % slug(blogs[0]), code=302)
url = QueryURL('/blog/%s' % slug(blogs[0]), search=search, **opt)()
return request.redirect(url, code=302)
date_begin, date_end = opt.get('date_begin'), opt.get('date_end')