From 6451a553c0108cccc2d5cef3c54108d358473444 Mon Sep 17 00:00:00 2001 From: Ravi Gohil Date: Fri, 3 Oct 2014 19:13:46 +0530 Subject: [PATCH] [FIX] website_blog: next post looping when last post The next post button at the bottom of an article was stuck when getting to the last page. A cookie storing the *all* the visited posts was used to determine the next one according to a non-stored (so not working) and unexpected criteria 'ranking'. Also could get articles from other blog. Instead of this whole broken logic, simple loop through articles by classic order and go back to first one when at the end. Better looping algorithm can be used in master where ranking is stored. Fixes #3097, opw 614559 --- addons/website_blog/controllers/main.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/addons/website_blog/controllers/main.py b/addons/website_blog/controllers/main.py index 5f2bea84df6..b8a7bf0ca03 100644 --- a/addons/website_blog/controllers/main.py +++ b/addons/website_blog/controllers/main.py @@ -199,17 +199,12 @@ class WebsiteBlog(http.Controller): tags = tag_obj.browse(cr, uid, tag_obj.search(cr, uid, [], context=context), context=context) # Find next Post - visited_blogs = request.httprequest.cookies.get('visited_blogs') or '' - visited_ids = filter(None, visited_blogs.split(',')) - visited_ids = map(lambda x: int(x), visited_ids) - if blog_post.id not in visited_ids: - visited_ids.append(blog_post.id) - next_post_id = blog_post_obj.search(cr, uid, [ - ('id', 'not in', visited_ids), - ], order='ranking desc', limit=1, context=context) - if not next_post_id: - next_post_id = blog_post_obj.search(cr, uid, [('id', '!=', blog.id)], order='ranking desc', limit=1, context=context) - next_post = next_post_id and blog_post_obj.browse(cr, uid, next_post_id[0], context=context) or False + all_post_ids = blog_post_obj.search(cr, uid, [('blog_id', '=', blog.id)], context=context) + # should always return at least the current post + current_blog_post_index = all_post_ids.index(blog_post.id) + next_post_id = all_post_ids[0 if current_blog_post_index == len(all_post_ids) - 1 \ + else current_blog_post_index + 1] + next_post = next_post_id and blog_post_obj.browse(cr, uid, next_post_id, context=context) or False values = { 'tags': tags, @@ -227,7 +222,6 @@ class WebsiteBlog(http.Controller): 'comments': comments, } response = request.website.render("website_blog.blog_post_complete", values) - response.set_cookie('visited_blogs', ','.join(map(str, visited_ids))) request.session[request.session_id] = request.session.get(request.session_id, []) if not (blog_post.id in request.session[request.session_id]):