[FIX] website_forum: fixed issue with user vote badly taken into account when upvotin...
authorThibault Delavallée <tde@openerp.com>
Wed, 9 Jul 2014 14:47:09 +0000 (16:47 +0200)
committerThibault Delavallée <tde@openerp.com>
Thu, 10 Jul 2014 07:03:53 +0000 (09:03 +0200)
addons/website_forum/models/forum.py
addons/website_forum/static/src/js/website_forum.js
addons/website_forum/views/website_forum.xml

index 43d10c5..a34eb10 100644 (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).
index aac2ba8..14e29d4 100644 (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");
index 15a1314..db054f8 100644 (file)
             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