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:
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).
}
} 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");
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 > 1" class="subtitle">
votes