Allow removing review votes

Fixes #328
This commit is contained in:
rubenwardy 2021-08-19 13:45:32 +01:00
parent 86e1f57198
commit c1edea4dc3

@ -161,15 +161,19 @@ def handle_review_vote(package: Package, review_id: int):
flash("You can't vote on your own reviews!", "danger")
return
is_positive = isYes(request.form["is_positive"])
vote = PackageReviewVote.query.filter_by(review=review, user=current_user).first()
if vote is None:
vote = PackageReviewVote()
vote.review = review
vote.user = current_user
vote.is_positive = isYes(request.form["is_positive"])
vote.is_positive = is_positive
db.session.add(vote)
elif vote.is_positive == is_positive:
db.session.delete(vote)
else:
vote.is_positive = isYes(request.form["is_positive"])
vote.is_positive = is_positive
review.update_score()
db.session.commit()