forked from rDrama/rDrama
refactor json a little bit and fix https://chapotraphouse.club/post/18459/marseycapywalking-megathread-for-bugs-and-suggestions/2278188?context=8#context
parent
bf1fec7918
commit
27b1ed83cc
|
@ -242,40 +242,6 @@ class Comment(Base):
|
||||||
if self.ghost: return '👻'
|
if self.ghost: return '👻'
|
||||||
else: return self.author.username
|
else: return self.author.username
|
||||||
|
|
||||||
@property
|
|
||||||
@lazy
|
|
||||||
def json_raw(self):
|
|
||||||
flags = {}
|
|
||||||
for f in self.flags: flags[f.user.username] = f.reason
|
|
||||||
|
|
||||||
data= {
|
|
||||||
'id': self.id,
|
|
||||||
'level': self.level,
|
|
||||||
'author_name': self.author_name,
|
|
||||||
'body': self.body,
|
|
||||||
'body_html': self.body_html,
|
|
||||||
'is_bot': self.is_bot,
|
|
||||||
'created_utc': self.created_utc,
|
|
||||||
'edited_utc': self.edited_utc or 0,
|
|
||||||
'is_banned': bool(self.is_banned),
|
|
||||||
'deleted_utc': self.deleted_utc,
|
|
||||||
'is_nsfw': self.over_18,
|
|
||||||
'permalink': f'/comment/{self.id}',
|
|
||||||
'stickied': self.stickied,
|
|
||||||
'distinguish_level': self.distinguish_level,
|
|
||||||
'post_id': self.post.id if self.post else 0,
|
|
||||||
'score': self.score,
|
|
||||||
'upvotes': self.upvotes,
|
|
||||||
'downvotes': self.downvotes,
|
|
||||||
'is_bot': self.is_bot,
|
|
||||||
'flags': flags,
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.ban_reason:
|
|
||||||
data["ban_reason"]=self.ban_reason
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
@lazy
|
@lazy
|
||||||
def award_count(self, kind, v):
|
def award_count(self, kind, v):
|
||||||
if v and v.poor: return 0
|
if v and v.poor: return 0
|
||||||
|
@ -300,13 +266,36 @@ class Comment(Base):
|
||||||
'parent': self.parent_fullname
|
'parent': self.parent_fullname
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
|
flags = {}
|
||||||
|
for f in self.flags: flags[f.user.username] = f.reason
|
||||||
|
|
||||||
data=self.json_raw
|
data= {
|
||||||
|
'id': self.id,
|
||||||
|
'level': self.level,
|
||||||
|
'author_name': self.author_name,
|
||||||
|
'body': self.body,
|
||||||
|
'body_html': self.body_html,
|
||||||
|
'is_bot': self.is_bot,
|
||||||
|
'created_utc': self.created_utc,
|
||||||
|
'edited_utc': self.edited_utc or 0,
|
||||||
|
'is_banned': bool(self.is_banned),
|
||||||
|
'deleted_utc': self.deleted_utc,
|
||||||
|
'is_nsfw': self.over_18,
|
||||||
|
'permalink': f'/comment/{self.id}',
|
||||||
|
'stickied': self.stickied,
|
||||||
|
'distinguish_level': self.distinguish_level,
|
||||||
|
'post_id': self.post.id if self.post else 0,
|
||||||
|
'score': self.score,
|
||||||
|
'upvotes': self.upvotes,
|
||||||
|
'downvotes': self.downvotes,
|
||||||
|
'is_bot': self.is_bot,
|
||||||
|
'flags': flags,
|
||||||
|
}
|
||||||
|
|
||||||
if self.level>=2: data['parent_comment_id']= self.parent_comment_id
|
|
||||||
|
|
||||||
if "replies" in self.__dict__:
|
if self.level >= 2: data['parent_comment_id'] = self.parent_comment_id
|
||||||
data['replies']=[x.json_core for x in self.replies(None)]
|
|
||||||
|
data['replies'] = [x.json_core for x in self.replies()]
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
|
@ -216,11 +216,30 @@ class Submission(Base):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def json_raw(self):
|
def json_core(self):
|
||||||
|
|
||||||
|
if self.is_banned:
|
||||||
|
return {'is_banned': True,
|
||||||
|
'deleted_utc': self.deleted_utc,
|
||||||
|
'ban_reason': self.ban_reason,
|
||||||
|
'id': self.id,
|
||||||
|
'title': self.title,
|
||||||
|
'permalink': self.permalink,
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.deleted_utc:
|
||||||
|
return {'is_banned': bool(self.is_banned),
|
||||||
|
'deleted_utc': True,
|
||||||
|
'id': self.id,
|
||||||
|
'title': self.title,
|
||||||
|
'permalink': self.permalink,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
flags = {}
|
flags = {}
|
||||||
for f in self.flags: flags[f.user.username] = f.reason
|
for f in self.flags: flags[f.user.username] = f.reason
|
||||||
|
|
||||||
data = {'author_name': self.author_name if self.author else '',
|
return {'author_name': self.author_name if self.author else '',
|
||||||
'permalink': self.permalink,
|
'permalink': self.permalink,
|
||||||
'shortlink': self.shortlink,
|
'shortlink': self.shortlink,
|
||||||
'is_banned': bool(self.is_banned),
|
'is_banned': bool(self.is_banned),
|
||||||
|
@ -249,33 +268,6 @@ class Submission(Base):
|
||||||
'club': self.club,
|
'club': self.club,
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.ban_reason:
|
|
||||||
data["ban_reason"]=self.ban_reason
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
@property
|
|
||||||
@lazy
|
|
||||||
def json_core(self):
|
|
||||||
|
|
||||||
if self.is_banned:
|
|
||||||
return {'is_banned': True,
|
|
||||||
'deleted_utc': self.deleted_utc,
|
|
||||||
'ban_reason': self.ban_reason,
|
|
||||||
'id': self.id,
|
|
||||||
'title': self.title,
|
|
||||||
'permalink': self.permalink,
|
|
||||||
}
|
|
||||||
elif self.deleted_utc:
|
|
||||||
return {'is_banned': bool(self.is_banned),
|
|
||||||
'deleted_utc': True,
|
|
||||||
'id': self.id,
|
|
||||||
'title': self.title,
|
|
||||||
'permalink': self.permalink,
|
|
||||||
}
|
|
||||||
|
|
||||||
return self.json_raw
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def json(self):
|
def json(self):
|
||||||
|
@ -288,7 +280,7 @@ class Submission(Base):
|
||||||
data["author"]='👻' if self.ghost else self.author.json_core
|
data["author"]='👻' if self.ghost else self.author.json_core
|
||||||
data["comment_count"]=self.comment_count
|
data["comment_count"]=self.comment_count
|
||||||
|
|
||||||
|
|
||||||
if "replies" in self.__dict__:
|
if "replies" in self.__dict__:
|
||||||
data["replies"]=[x.json_core for x in self.replies]
|
data["replies"]=[x.json_core for x in self.replies]
|
||||||
|
|
||||||
|
|
|
@ -619,8 +619,19 @@ class User(Base):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def json_raw(self):
|
def json_core(self):
|
||||||
data = {'username': self.username,
|
|
||||||
|
if self.is_suspended:
|
||||||
|
return {'username': self.username,
|
||||||
|
'url': self.url,
|
||||||
|
'is_banned': True,
|
||||||
|
'is_permanent_ban': not bool(self.unban_utc),
|
||||||
|
'ban_reason': self.ban_reason,
|
||||||
|
'id': self.id
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return {'username': self.username,
|
||||||
'url': self.url,
|
'url': self.url,
|
||||||
'is_banned': bool(self.is_banned),
|
'is_banned': bool(self.is_banned),
|
||||||
'created_utc': self.created_utc,
|
'created_utc': self.created_utc,
|
||||||
|
@ -633,22 +644,6 @@ class User(Base):
|
||||||
'flair': self.customtitle
|
'flair': self.customtitle
|
||||||
}
|
}
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
@property
|
|
||||||
@lazy
|
|
||||||
def json_core(self):
|
|
||||||
|
|
||||||
now = int(time.time())
|
|
||||||
if self.is_suspended:
|
|
||||||
return {'username': self.username,
|
|
||||||
'url': self.url,
|
|
||||||
'is_banned': True,
|
|
||||||
'is_permanent_ban': not bool(self.unban_utc),
|
|
||||||
'ban_reason': self.ban_reason,
|
|
||||||
'id': self.id
|
|
||||||
}
|
|
||||||
return self.json_raw
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
|
|
Loading…
Reference in New Issue