From e7ce39bd80eebbc828796548a4afdd5699404048 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 26 Jun 2022 22:53:12 +0200 Subject: [PATCH] fix poll-voting --- files/classes/comment.py | 4 ++-- files/classes/submission.py | 4 ++-- files/routes/votes.py | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index 26c0816d4..0bc447fde 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -135,8 +135,8 @@ class Comment(Base): @lazy def total_choice_voted(self, v): if v: - return g.db.query(CommentVote.comment_id).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).first() - return False + return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).first() + return None @property @lazy diff --git a/files/classes/submission.py b/files/classes/submission.py index 596deed5f..3611c0dcb 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -128,8 +128,8 @@ class Submission(Base): @lazy def total_choice_voted(self, v): if v and self.choices: - return g.db.query(CommentVote.comment_id).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).first() - return False + return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).first() + return None @lazy def total_bet_voted(self, v): diff --git a/files/routes/votes.py b/files/routes/votes.py index fbeac116c..f76583431 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -278,7 +278,8 @@ def api_vote_choice(comment_id, v): if comment.parent_comment: parent = comment.parent_comment else: parent = comment.post - for vote in parent.total_choice_voted(v): + vote = parent.total_choice_voted(v) + if vote: vote.comment.upvotes = g.db.query(CommentVote).filter_by(comment_id=vote.comment.id, vote_type=1).count() - 1 g.db.add(vote.comment) g.db.delete(vote)