First time here? Check out the FAQ!
2

on trying to upvote again previous vote gets cancelled!

when i try to upvote a post that i have upvoted previously the previous vote gets cancelled and score gets reduced.

same problem occurs when i try to downvote a post that i have previously downvoted. Is this the desired behavior?

vikas.gulati's avatar
21
vikas.gulati
asked 2012-09-27 08:58:47 -0600
edit flag offensive 0 remove flag close merge delete

Comments

Maybe it's not the best way, how would you suggest to handle this situation?

Evgeny's avatar Evgeny (2012-09-27 12:10:50 -0600) edit

desired behavior should be that previous vote shall only be cancelled if my current vote and old vote are opposites otherwise it shouldn't.

to tackle this situation i had to override the process_vote method and added a check before vote.cancel() as mentioned below in my answer.

vikas.gulati's avatar vikas.gulati (2012-09-27 12:27:21 -0600) edit

Not sure if it's a big deal, this is the first time someone identified this as a problem in more than two years.

Evgeny's avatar Evgeny (2012-09-27 16:45:16 -0600) edit

What if you wanted to cancel your upvote without downvoting (or vice versa)?

todofixthis's avatar todofixthis (2012-09-27 22:51:51 -0600) edit
add a comment see more comments

1 Answer

0

what i did was to override the process_vote method and change the line which says:

score_delta = vote.cancel()
response_data['count'] = post.score + score_delta
response_data['status'] = 1 #this means "cancel"

to this:

before_vote = vote.vote

if (before_vote<0 and vote_direction == 'up') or (before_vote>0 and vote_direction == 'down'):
    score_delta = vote.cancel()
    response_data['count'] = post.score + score_delta
    response_data['status'] = 1 #this means "cancel"
vikas.gulati's avatar
21
vikas.gulati
answered 2012-09-27 12:30:48 -0600
todofixthis's avatar
1.3k
todofixthis
updated 2012-09-28 08:46:11 -0600
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments