forked from rDrama/rDrama
1
0
Fork 0

fix poll-voting

master
Aevann1 2022-06-26 22:53:12 +02:00
parent 8185340e15
commit e7ce39bd80
3 changed files with 6 additions and 5 deletions

View File

@ -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

View File

@ -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):

View File

@ -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)