refactor json again
parent
bc4074f9aa
commit
ae45b45bfb
|
@ -248,8 +248,7 @@ class Comment(Base):
|
|||
return len([x for x in self.awards if x.kind == kind])
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def json_core(self):
|
||||
def json(self):
|
||||
if self.is_banned:
|
||||
data= {'is_banned': True,
|
||||
'ban_reason': self.ban_reason,
|
||||
|
@ -290,28 +289,11 @@ class Comment(Base):
|
|||
'downvotes': self.downvotes,
|
||||
'is_bot': self.is_bot,
|
||||
'flags': flags,
|
||||
'author': '👻' if self.ghost else self.author.json,
|
||||
'replies': [x.json for x in self.replies()]
|
||||
}
|
||||
|
||||
|
||||
if self.level >= 2: data['parent_comment_id'] = self.parent_comment_id
|
||||
|
||||
return data
|
||||
|
||||
@property
|
||||
def json(self):
|
||||
|
||||
data=self.json_core
|
||||
|
||||
if self.deleted_utc or self.is_banned:
|
||||
return data
|
||||
|
||||
data["author"]='👻' if self.ghost else self.author.json_core
|
||||
data["post"]=self.post.json_core if self.post else ''
|
||||
|
||||
if self.level >= 2:
|
||||
data["parent"]=self.parent.json_core
|
||||
|
||||
data['replies'] = [x.json_core for x in self.replies()]
|
||||
|
||||
return data
|
||||
|
||||
|
|
|
@ -216,7 +216,7 @@ class Submission(Base):
|
|||
|
||||
@property
|
||||
@lazy
|
||||
def json_core(self):
|
||||
def json(self):
|
||||
|
||||
if self.is_banned:
|
||||
return {'is_banned': True,
|
||||
|
@ -239,7 +239,7 @@ class Submission(Base):
|
|||
flags = {}
|
||||
for f in self.flags: flags[f.user.username] = f.reason
|
||||
|
||||
return {'author_name': self.author_name if self.author else '',
|
||||
data = {'author_name': self.author_name if self.author else '',
|
||||
'permalink': self.permalink,
|
||||
'shortlink': self.shortlink,
|
||||
'is_banned': bool(self.is_banned),
|
||||
|
@ -266,27 +266,14 @@ class Submission(Base):
|
|||
'voted': self.voted if hasattr(self, 'voted') else 0,
|
||||
'flags': flags,
|
||||
'club': self.club,
|
||||
'author': '👻' if self.ghost else self.author.json,
|
||||
'comment_count': self.comment_count,
|
||||
'voted': self.voted
|
||||
}
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def json(self):
|
||||
|
||||
data=self.json_core
|
||||
|
||||
if self.deleted_utc or self.is_banned:
|
||||
return data
|
||||
|
||||
data["author"]='👻' if self.ghost else self.author.json_core
|
||||
data["comment_count"]=self.comment_count
|
||||
|
||||
|
||||
if "replies" in self.__dict__:
|
||||
data["replies"]=[x.json for x in self.replies]
|
||||
|
||||
if "voted" in self.__dict__:
|
||||
data["voted"] = self.voted
|
||||
|
||||
return data
|
||||
|
||||
@lazy
|
||||
|
|
|
@ -620,8 +620,7 @@ class User(Base):
|
|||
|
||||
@property
|
||||
@lazy
|
||||
def json_core(self):
|
||||
|
||||
def json(self):
|
||||
if self.is_suspended:
|
||||
return {'username': self.username,
|
||||
'url': self.url,
|
||||
|
@ -642,22 +641,14 @@ class User(Base):
|
|||
'bannerurl': self.banner_url,
|
||||
'bio': self.bio,
|
||||
'bio_html': self.bio_html_eager,
|
||||
'flair': self.customtitle
|
||||
'flair': self.customtitle,
|
||||
'badges': [x.json for x in self.badges],
|
||||
'coins': self.coins,
|
||||
'post_count': self.post_count,
|
||||
'comment_count': self.comment_count
|
||||
}
|
||||
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def json(self):
|
||||
data = self.json_core
|
||||
|
||||
data["badges"] = [x.json for x in self.badges]
|
||||
data['coins'] = self.coins
|
||||
data['post_count'] = self.post_count
|
||||
data['comment_count'] = self.comment_count
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def ban(self, admin=None, reason=None, days=0):
|
||||
if days:
|
||||
|
|
|
@ -25,24 +25,15 @@ class Vote(Base):
|
|||
def __repr__(self):
|
||||
return f"<Vote(id={self.id})>"
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def json_core(self):
|
||||
data={
|
||||
"user_id": self.user_id,
|
||||
"submission_id":self.submission_id,
|
||||
"vote_type":self.vote_type
|
||||
}
|
||||
return data
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def json(self):
|
||||
data=self.json_core
|
||||
data["user"]=self.user.json_core
|
||||
data["post"]=self.post.json_core
|
||||
|
||||
return data
|
||||
return {"user_id": self.user_id,
|
||||
"submission_id":self.submission_id,
|
||||
"vote_type":self.vote_type,
|
||||
"user":self.user.json,
|
||||
"post":self.post.json
|
||||
}
|
||||
|
||||
class CommentVote(Base):
|
||||
|
||||
|
@ -64,21 +55,12 @@ class CommentVote(Base):
|
|||
def __repr__(self):
|
||||
return f"<CommentVote(id={self.id})>"
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def json_core(self):
|
||||
data={
|
||||
"user_id": self.user_id,
|
||||
"comment_id":self.comment_id,
|
||||
"vote_type":self.vote_type
|
||||
}
|
||||
return data
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def json(self):
|
||||
data=self.json_core
|
||||
data["user"]=self.user.json_core
|
||||
data["comment"]=self.comment.json_core
|
||||
|
||||
return data
|
||||
return {"user_id": self.user_id,
|
||||
"submission_id":self.submission_id,
|
||||
"vote_type":self.vote_type,
|
||||
"user":self.user.json,
|
||||
"comment":self.comment.json
|
||||
}
|
|
@ -30,7 +30,7 @@ def unread(v):
|
|||
n.read = True
|
||||
g.db.add(n)
|
||||
|
||||
return {"data":[x[1].json_core for x in listing]}
|
||||
return {"data":[x[1].json for x in listing]}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue