From abbe4ef76ce0e6fdbf71effbad922c06df9a59b9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 9 Jul 2014 16:47:09 +0200 Subject: [PATCH] [FIX] website_forum: fixed issue with user vote badly taken into account when upvoting / downvoting + crash due to wrong field name. Backport of Leonardo Donelli PR for master. --- addons/website_forum/models/forum.py | 3 ++- addons/website_forum/static/src/js/website_forum.js | 4 ++-- addons/website_forum/views/website_forum.xml | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py index 43d10c5..a34eb10 100644 --- a/addons/website_forum/models/forum.py +++ b/addons/website_forum/models/forum.py @@ -401,6 +401,7 @@ class Post(osv.Model): Vote = self.pool['forum.post.vote'] vote_ids = Vote.search(cr, uid, [('post_id', 'in', ids), ('user_id', '=', uid)], limit=1, context=context) + new_vote = 0 if vote_ids: for vote in Vote.browse(cr, uid, vote_ids, context=context): if upvote: @@ -412,7 +413,7 @@ class Post(osv.Model): for post_id in ids: new_vote = '1' if upvote else '-1' Vote.create(cr, uid, {'post_id': post_id, 'vote': new_vote}, context=context) - return {'vote_count': self._get_vote_count(cr, uid, ids, None, None, context=context)[ids[0]]} + return {'vote_count': self._get_vote_count(cr, uid, ids, None, None, context=context)[ids[0]], 'user_vote': new_vote} def convert_answer_to_comment(self, cr, uid, id, context=None): """ Tools to convert an answer (forum.post) to a comment (mail.message). diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js index aac2ba8..14e29d4 100644 --- a/addons/website_forum/static/src/js/website_forum.js +++ b/addons/website_forum/static/src/js/website_forum.js @@ -38,11 +38,11 @@ $(document).ready(function () { } } else { $link.parent().find("#vote_count").html(data['vote_count']); - if (data['vote_count'] == 0) { + if (data['user_vote'] == 0) { $link.parent().find(".text-success").removeClass("text-success"); $link.parent().find(".text-warning").removeClass("text-warning"); } else { - if (data['vote_count'] == 1) { + if (data['user_vote'] == 1) { $link.addClass("text-success"); } else { $link.addClass("text-warning"); diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index 15a1314..db054f8 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -424,7 +424,7 @@ t-attf-data-href="/forum/#{slug(post.forum_id)}/post/#{slug(post)}/upvote"/>
votes -- 1.7.10.4