[IMP] website_slides: create hook to update slides values

With the integration slides-knowledge,
slides can be set on the team, so that the user can be redirected
to them when searching for help.
We want to use the same view as for all slides,
but limit the records presented to the user.

With this commit, we create two distinct methods:
one that prepares the values
one that renders them.
This way, we can hook into the first one to replace the records
before rendering them, when the `/helpdesk/<team_id>/slides`
route is used.

task-2890043

closes odoo/odoo#97739

Related: odoo/enterprise#29283
Signed-off-by: Laurent Stukkens (ltu) <ltu@odoo.com>
This commit is contained in:
Audric Onockx (auon)
2022-09-13 07:37:56 +02:00
committed by Laurent Stukkens (LTU)
parent 927ec413c5
commit 0cc8e582ca
+15 -17
View File
@@ -345,6 +345,20 @@ class WebsiteSlides(WebsiteProfile):
@http.route(['/slides/all', '/slides/all/tag/<string:slug_tags>'], type='http', auth="public", website=True, sitemap=True)
def slides_channel_all(self, slide_category=None, slug_tags=None, my=False, **post):
if slug_tags and request.httprequest.method == 'GET':
# Redirect `tag-1,tag-2` to `tag-1` to disallow multi tags
# in GET request for proper bot indexation;
# if the search term is available, do not remove any existing
# tags because it is user who provided search term with GET
# request and so clearly it's not SEO bot.
tag_list = slug_tags.split(',')
if len(tag_list) > 1 and not post.get('search'):
url = QueryURL('/slides/all', ['tag'], tag=tag_list[0], my=my, slide_category=slide_category)()
return request.redirect(url, code=302)
render_values = self.slides_channel_all_values(slide_category=slide_category, slug_tags=slug_tags, my=my, **post)
return request.render('website_slides.courses_all', render_values)
def slides_channel_all_values(self, slide_category=None, slug_tags=None, my=False, **post):
""" Home page displaying a list of courses displayed according to some
criterion and search terms.
@@ -359,22 +373,6 @@ class WebsiteSlides(WebsiteProfile):
* ``search``: filter on course description / name;
"""
# retro-compatibility for older links, 'slide_category' field was previously named 'slide_type'
# can be safely removed after 15.3 (I swear though, don't be afraid, remove it!)
slide_category = slide_category or post.get('slide_type')
if slug_tags and request.httprequest.method == 'GET':
# Redirect `tag-1,tag-2` to `tag-1` to disallow multi tags
# in GET request for proper bot indexation;
# if the search term is available, do not remove any existing
# tags because it is user who provided search term with GET
# request and so clearly it's not SEO bot.
tag_list = slug_tags.split(',')
if len(tag_list) > 1 and not post.get('search'):
url = QueryURL('/slides/all', ['tag'], tag=tag_list[0], my=my, slide_category=slide_category)()
return request.redirect(url, code=302)
options = {
'displayDescription': True,
'displayDetail': False,
@@ -416,7 +414,7 @@ class WebsiteSlides(WebsiteProfile):
'slide_query_url': QueryURL('/slides/all', ['tag']),
})
return request.render('website_slides.courses_all', render_values)
return render_values
def _prepare_additional_channel_values(self, values, **kwargs):
return values