forked from rDrama/rDrama
add more @lazy to functions
parent
39cf7fc48b
commit
ceb72a470c
|
@ -122,13 +122,14 @@ class Comment(Base):
|
||||||
def choices(self):
|
def choices(self):
|
||||||
return self.child_comments.filter_by(author_id=AUTOCHOICE_ID).order_by(Comment.id).all()
|
return self.child_comments.filter_by(author_id=AUTOCHOICE_ID).order_by(Comment.id).all()
|
||||||
|
|
||||||
|
@lazy
|
||||||
def total_poll_voted(self, v):
|
def total_poll_voted(self, v):
|
||||||
if v:
|
if v:
|
||||||
for option in self.options:
|
for option in self.options:
|
||||||
if option.poll_voted(v): return True
|
if option.poll_voted(v): return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@lazy
|
||||||
def total_choice_voted(self, v):
|
def total_choice_voted(self, v):
|
||||||
if v:
|
if v:
|
||||||
return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).all()
|
return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).all()
|
||||||
|
@ -321,6 +322,7 @@ class Comment(Base):
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@lazy
|
||||||
def award_count(self, kind):
|
def award_count(self, kind):
|
||||||
return len([x for x in self.awards if x.kind == kind])
|
return len([x for x in self.awards if x.kind == kind])
|
||||||
|
|
||||||
|
@ -354,7 +356,6 @@ class Comment(Base):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
|
||||||
def json(self):
|
def json(self):
|
||||||
|
|
||||||
data=self.json_core
|
data=self.json_core
|
||||||
|
@ -371,6 +372,7 @@ class Comment(Base):
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@lazy
|
||||||
def realbody(self, v):
|
def realbody(self, v):
|
||||||
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id])): return f"<p>{CC} ONLY</p>"
|
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id])): return f"<p>{CC} ONLY</p>"
|
||||||
|
|
||||||
|
@ -435,6 +437,7 @@ class Comment(Base):
|
||||||
|
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
@lazy
|
||||||
def plainbody(self, v):
|
def plainbody(self, v):
|
||||||
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id])): return f"<p>{CC} ONLY</p>"
|
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id])): return f"<p>{CC} ONLY</p>"
|
||||||
|
|
||||||
|
|
|
@ -117,17 +117,20 @@ class Submission(Base):
|
||||||
def bet_options(self):
|
def bet_options(self):
|
||||||
return g.db.query(Comment).filter_by(parent_submission = self.id, author_id = AUTOBETTER_ID, level=1).all()
|
return g.db.query(Comment).filter_by(parent_submission = self.id, author_id = AUTOBETTER_ID, level=1).all()
|
||||||
|
|
||||||
|
@lazy
|
||||||
def total_poll_voted(self, v):
|
def total_poll_voted(self, v):
|
||||||
if v:
|
if v:
|
||||||
for option in self.options:
|
for option in self.options:
|
||||||
if option.poll_voted(v): return True
|
if option.poll_voted(v): return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@lazy
|
||||||
def total_choice_voted(self, v):
|
def total_choice_voted(self, v):
|
||||||
if v and self.choices:
|
if v and self.choices:
|
||||||
return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).all()
|
return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).all()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@lazy
|
||||||
def total_bet_voted(self, v):
|
def total_bet_voted(self, v):
|
||||||
if "closed" in self.body.lower(): return True
|
if "closed" in self.body.lower(): return True
|
||||||
if v:
|
if v:
|
||||||
|
@ -361,6 +364,7 @@ class Submission(Base):
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@lazy
|
||||||
def award_count(self, kind):
|
def award_count(self, kind):
|
||||||
return len([x for x in self.awards if x.kind == kind])
|
return len([x for x in self.awards if x.kind == kind])
|
||||||
|
|
||||||
|
@ -381,7 +385,7 @@ class Submission(Base):
|
||||||
|
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
@lazy
|
||||||
def realbody(self, v):
|
def realbody(self, v):
|
||||||
if self.club and not (v and (v.paid_dues or v.id == self.author_id)): return f"<p>{CC} ONLY</p>"
|
if self.club and not (v and (v.paid_dues or v.id == self.author_id)): return f"<p>{CC} ONLY</p>"
|
||||||
|
|
||||||
|
@ -443,6 +447,7 @@ class Submission(Base):
|
||||||
|
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
@lazy
|
||||||
def plainbody(self, v):
|
def plainbody(self, v):
|
||||||
if self.club and not (v and (v.paid_dues or v.id == self.author_id)): return f"<p>{CC} ONLY</p>"
|
if self.club and not (v and (v.paid_dues or v.id == self.author_id)): return f"<p>{CC} ONLY</p>"
|
||||||
|
|
||||||
|
|
|
@ -256,9 +256,11 @@ class User(Base):
|
||||||
return return_value
|
return return_value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@lazy
|
||||||
def referral_count(self):
|
def referral_count(self):
|
||||||
return len(self.referrals)
|
return len(self.referrals)
|
||||||
|
|
||||||
|
@lazy
|
||||||
def is_blocking(self, target):
|
def is_blocking(self, target):
|
||||||
return g.db.query(UserBlock).filter_by(user_id=self.id, target_id=target.id).one_or_none()
|
return g.db.query(UserBlock).filter_by(user_id=self.id, target_id=target.id).one_or_none()
|
||||||
|
|
||||||
|
@ -358,6 +360,7 @@ class User(Base):
|
||||||
if not self.is_suspended: return None
|
if not self.is_suspended: return None
|
||||||
return g.db.get(User, self.is_banned)
|
return g.db.get(User, self.is_banned)
|
||||||
|
|
||||||
|
@lazy
|
||||||
def has_badge(self, badge_id):
|
def has_badge(self, badge_id):
|
||||||
return g.db.query(Badge).filter_by(user_id=self.id, badge_id=badge_id).one_or_none()
|
return g.db.query(Badge).filter_by(user_id=self.id, badge_id=badge_id).one_or_none()
|
||||||
|
|
||||||
|
@ -564,6 +567,7 @@ class User(Base):
|
||||||
modded_subs = g.db.query(Mod.sub).filter_by(user_id=self.id).all()
|
modded_subs = g.db.query(Mod.sub).filter_by(user_id=self.id).all()
|
||||||
return modded_subs
|
return modded_subs
|
||||||
|
|
||||||
|
@lazy
|
||||||
def has_follower(self, user):
|
def has_follower(self, user):
|
||||||
|
|
||||||
return g.db.query(Follow).filter_by(target_id=self.id, user_id=user.id).one_or_none()
|
return g.db.query(Follow).filter_by(target_id=self.id, user_id=user.id).one_or_none()
|
||||||
|
@ -657,6 +661,7 @@ class User(Base):
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@lazy
|
||||||
def is_suspended(self):
|
def is_suspended(self):
|
||||||
return (self.is_banned and (self.unban_utc == 0 or self.unban_utc > time.time()))
|
return (self.is_banned and (self.unban_utc == 0 or self.unban_utc > time.time()))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue