Merge pull request #30 from LQDJudge/pagevote

fix bugs
This commit is contained in:
Phuoc Dinh Le 2022-11-17 13:08:01 -06:00 committed by GitHub
commit 36511d1a13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 15 deletions

View file

@ -71,10 +71,6 @@ def vote_page(request, delta):
except PageVoteVoter.DoesNotExist: except PageVoteVoter.DoesNotExist:
# We must continue racing in case this is exploited to manipulate votes. # We must continue racing in case this is exploited to manipulate votes.
continue continue
if -vote.score != delta:
return HttpResponseBadRequest(
_("You already voted."), content_type="text/plain"
)
vote.delete() vote.delete()
PageVote.objects.filter(id=pagevote_id).update( PageVote.objects.filter(id=pagevote_id).update(
score=F("score") - vote.score score=F("score") - vote.score

View file

@ -41,11 +41,13 @@
if ($votes.downvote.hasClass('voted')) { if ($votes.downvote.hasClass('voted')) {
delta = 2; delta = 2;
} }
ajax_vote('{{ url('pagevote_upvote') }}', id, delta, function () { for (let i = 0; i < delta; i++) {
if ($votes.downvote.hasClass('voted')) ajax_vote('{{ url('pagevote_upvote') }}', id, 1, function () {
$votes.downvote.removeClass('voted'); if ($votes.downvote.hasClass('voted'))
$votes.upvote.addClass('voted'); $votes.downvote.removeClass('voted');
}); $votes.upvote.addClass('voted');
});
}
} }
}; };
@ -61,11 +63,13 @@
if ($votes.upvote.hasClass('voted')) { if ($votes.upvote.hasClass('voted')) {
delta = -2; delta = -2;
} }
ajax_vote('{{ url('pagevote_downvote') }}', id, delta, function () { for (let i = 0; i > delta; i--) {
if ($votes.upvote.hasClass('voted')) ajax_vote('{{ url('pagevote_downvote') }}', id, -1, function () {
$votes.upvote.removeClass('voted'); if ($votes.upvote.hasClass('voted'))
$votes.downvote.addClass('voted'); $votes.upvote.removeClass('voted');
}); $votes.downvote.addClass('voted');
});
}
} }
}; };

View file

@ -18,7 +18,7 @@
</script> </script>
{% include "contest/media-js.html" %} {% include "contest/media-js.html" %}
{% include "comments/media-js.html" %} {% include "comments/media-js.html" %}
{% include "actionbar/media-css.html" %} {% include "actionbar/media-js.html" %}
{% endblock %} {% endblock %}
{% block content_media %} {% block content_media %}