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:
# We must continue racing in case this is exploited to manipulate votes.
continue
if -vote.score != delta:
return HttpResponseBadRequest(
_("You already voted."), content_type="text/plain"
)
vote.delete()
PageVote.objects.filter(id=pagevote_id).update(
score=F("score") - vote.score

View file

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

View file

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