From 0cc8e582ca9fb3714461d9f36b52883bb10c7751 Mon Sep 17 00:00:00 2001 From: "Audric Onockx (auon)" Date: Mon, 8 Aug 2022 15:33:23 +0000 Subject: [PATCH] [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//slides` route is used. task-2890043 closes odoo/odoo#97739 Related: odoo/enterprise#29283 Signed-off-by: Laurent Stukkens (ltu) --- addons/website_slides/controllers/main.py | 32 +++++++++++------------ 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/addons/website_slides/controllers/main.py b/addons/website_slides/controllers/main.py index db4088d193f..fbd4707c40a 100644 --- a/addons/website_slides/controllers/main.py +++ b/addons/website_slides/controllers/main.py @@ -345,6 +345,20 @@ class WebsiteSlides(WebsiteProfile): @http.route(['/slides/all', '/slides/all/tag/'], 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