[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.

This commit is contained in:
Thibault Delavallée 2014-07-09 16:47:09 +02:00
parent b333457ca3
commit abbe4ef76c
3 changed files with 5 additions and 4 deletions

View File

@ -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).

View File

@ -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");

View File

@ -424,7 +424,7 @@
t-attf-data-href="/forum/#{slug(post.forum_id)}/post/#{slug(post)}/upvote"/>
<span id="vote_count" t-esc="post.vote_count"/>
<a t-attf-class="vote_down fa fa-thumbs-down no-decoration #{post.user_vote == -1 and 'text-warning' or ''} #{((post.user_vote == -1 and not post.can_upvote) or not post.can_downvote) and 'karma_required' or ''}"
t-attf-data-karma="#{post.user_vote == -1 and post.karma_uovote or post.karma_downvote}"
t-attf-data-karma="#{post.user_vote == -1 and post.karma_upvote or post.karma_downvote}"
t-attf-data-href="/forum/#{slug(post.forum_id)}/post/#{slug(post)}/downvote"/>
<div t-if="vote_count &gt; 1" class="subtitle">
votes