This commit is contained in:
Aevann1 2021-07-25 23:59:20 +02:00
parent 4b89a5b6db
commit a4eeee5a11
68 changed files with 3376 additions and 2605 deletions

View file

@ -34,14 +34,11 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
parent_submission = Column(Integer, ForeignKey("submissions.id"))
# this column is foreignkeyed to comment(id) but we can't do that yet as
# "comment" class isn't yet defined
parent_fullname = Column(Integer)
created_utc = Column(Integer, default=0)
edited_utc = Column(Integer, default=0)
is_banned = Column(Boolean, default=False)
shadowbanned = Column(Boolean, default=False)
distinguish_level = Column(Integer, default=0)
gm_distinguish = Column(Integer, ForeignKey("boards.id"), default=0)
distinguished_board = relationship("Board", lazy="joined", primaryjoin="Comment.gm_distinguish==Board.id")
deleted_utc = Column(Integer, default=0)
purged_utc = Column(Integer, default=0)
is_approved = Column(Integer, default=0)
@ -51,11 +48,8 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
score_top = Column(Integer, default=1)
level = Column(Integer, default=0)
parent_comment_id = Column(Integer, ForeignKey("comments.id"))
original_board_id = Column(Integer, ForeignKey("boards.id"))
over_18 = Column(Boolean, default=False)
is_offensive = Column(Boolean, default=False)
is_nsfl = Column(Boolean, default=False)
is_bot = Column(Boolean, default=False)
banaward = Column(String, default=None)
is_pinned = Column(Boolean, default=False)
@ -72,9 +66,6 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
lazy="joined",
innerjoin=True,
primaryjoin="User.id==Comment.author_id")
board = association_proxy("post", "board")
original_board = relationship(
"Board", primaryjoin="Board.id==Comment.original_board_id")
upvotes = Column(Integer, default=1)
downvotes = Column(Integer, default=0)
@ -95,8 +86,6 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
rank_fiery = deferred(Column(Float, server_default=FetchedValue()))
rank_hot = deferred(Column(Float, server_default=FetchedValue()))
board_id = deferred(Column(Integer, server_default=FetchedValue()))
def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs:
@ -115,28 +104,9 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
def score_disputed(self):
return (self.upvotes+1) * (self.downvotes+1)
@property
@lazy
def fullname(self):
return f"t3_{self.base36id}"
def children(self, v):
return sorted([x for x in self.child_comments if not x.author.shadowbanned or (v and v.id == x.author_id)], key=lambda x: x.score, reverse=True)
@property
@lazy
def is_deleted(self):
return bool(self.deleted_utc)
@property
@lazy
def is_top_level(self):
return self.parent_fullname and self.parent_fullname.startswith("t2_")
@property
def is_archived(self):
return self.post.is_archived
@property
@lazy
def parent(self):
@ -144,7 +114,7 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
if not self.parent_submission:
return None
if self.is_top_level:
if self.level == 1:
return self.post
else:
@ -229,27 +199,13 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
else:
return self.flag_count
def visibility_reason(self, v):
if not v or self.author_id == v.id:
return "this is your content."
elif not self.board:
return None
elif self.board.has_mod(v):
return f"you are a guildmaster of +{self.board.name}."
elif self.board.has_contributor(v):
return f"you are an approved contributor in +{self.board.name}."
elif self.parent.author_id == v.id:
return "this is a reply to your content."
elif v.admin_level >= 4:
return "you are a Drama admin."
@property
def json_raw(self):
data= {
'id': self.base36id,
'fullname': self.fullname,
'level': self.level,
'author_name': self.author.username if not self.author.is_deleted else None,
'author_name': self.author.username if not self.author.deleted_utc > 0 else None,
'body': self.body,
'body_html': self.body_html,
'is_archived': self.is_archived,
@ -257,10 +213,9 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
'created_utc': self.created_utc,
'edited_utc': self.edited_utc or 0,
'is_banned': bool(self.is_banned),
'is_deleted': self.is_deleted,
'deleted_utc': self.deleted_utc,
'is_nsfw': self.over_18,
'is_offensive': self.is_offensive,
'is_nsfl': self.is_nsfl,
'permalink': self.permalink,
'post_id': self.post.base36id,
'score': self.score_fuzzed,
@ -284,14 +239,12 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
'id': self.base36id,
'post': self.post.base36id,
'level': self.level,
'parent': self.parent_fullname
}
elif self.deleted_utc > 0:
data= {'deleted_utc': self.deleted_utc,
'id': self.base36id,
'post': self.post.base36id,
'level': self.level,
'parent': self.parent_fullname
}
else:
@ -315,7 +268,6 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
data["author"]=self.author.json_core
data["post"]=self.post.json_core
data["guild"]=self.post.board.json_core
if self.level >= 2:
data["parent"]=self.parent.json_core
@ -435,7 +387,6 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
"deleted_utc": self.deleted_utc,
'created_utc': self.created_utc,
'id': self.base36id,
'fullname': self.fullname,
'permalink': self.permalink,
'post_id': self.post.base36id,
'level': self.level
@ -461,7 +412,7 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
@property
@lazy
def is_op(self):
return self.author_id==self.post.author_id and not self.author.is_deleted and not self.post.author.is_deleted and not self.post.is_deleted
return self.author_id==self.post.author_id and not self.author.deleted_utc > 0 and not self.post.author.deleted_utc > 0 and not self.post.deleted_utc