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?

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
vikas.gulati's avatar
21
vikas.gulati
asked 12 years ago

Comments

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

Evgeny's avatar Evgeny (12 years ago)

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 (12 years ago)

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 (12 years ago)

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

todofixthis's avatar todofixthis (12 years ago)
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"

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
vikas.gulati's avatar
21
vikas.gulati
answered 12 years ago
todofixthis's avatar
1.3k
todofixthis
updated 12 years ago
link

Comments

see more comments