Skip to content

Commit

Permalink
[FIX] website_blog: next post looping when last post
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rgo-odoo authored and mart-e committed Jan 30, 2015
1 parent 2883e3f commit 6451a55
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions addons/website_blog/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,12 @@ def blog_post(self, blog, blog_post, tag_id=None, page=1, enable_editor=None, **
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,
Expand All @@ -227,7 +222,6 @@ def blog_post(self, blog, blog_post, tag_id=None, page=1, enable_editor=None, **
'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]):
Expand Down

0 comments on commit 6451a55

Please sign in to comment.