Ask Your Question
2

on trying to upvote again previous vote gets cancelled!

asked 2012-09-27 08:58:47 -0600

vikas.gulati gravatar image

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?

edit retag flag offensive close merge delete

Comments

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

Evgeny gravatar imageEvgeny ( 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 gravatar imagevikas.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 gravatar imageEvgeny ( 2012-09-27 16:45:16 -0600 )edit

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

todofixthis gravatar imagetodofixthis ( 2012-09-27 22:51:51 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2012-09-27 12:30:48 -0600

vikas.gulati gravatar image

updated 2012-09-28 08:46:11 -0600

todofixthis gravatar image

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"
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-09-27 08:58:47 -0600

Seen: 69 times

Last updated: Sep 28 '12