From 2c81db79efcfd111495a1dc16574ca2a823caf69 Mon Sep 17 00:00:00 2001 From: TLSM Date: Fri, 18 Nov 2022 15:33:07 -0500 Subject: [PATCH] Fix API for /comment/, /search/comments. --- files/classes/votes.py | 24 ++++++++++++------------ files/routes/comments.py | 4 ++-- files/routes/search.py | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/files/classes/votes.py b/files/classes/votes.py index cfb6b1889..024bc1e3d 100644 --- a/files/classes/votes.py +++ b/files/classes/votes.py @@ -30,12 +30,12 @@ class Vote(Base): @property @lazy def json(self): - return {"user_id": self.user_id, - "submission_id":self.submission_id, - "vote_type":self.vote_type, - "user":self.user.json, - "post":self.post.json - } + return { + "user_id": self.user_id, + "submission_id": self.submission_id, + "vote_type": self.vote_type, + "user": self.user.json, + } class CommentVote(Base): @@ -61,9 +61,9 @@ class CommentVote(Base): @property @lazy def json(self): - return {"user_id": self.user_id, - "submission_id":self.submission_id, - "vote_type":self.vote_type, - "user":self.user.json, - "comment":self.comment.json - } + return { + "user_id": self.user_id, + "submission_id": self.submission_id, + "vote_type": self.vote_type, + "user": self.user.json, + } diff --git a/files/routes/comments.py b/files/routes/comments.py index 16426e10a..791faf274 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -73,7 +73,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None): execute_shadowban_viewers_and_voters(v, post) execute_shadowban_viewers_and_voters(v, comment) - if v and v.client: return top_comment.json + if v and v.client: return top_comment.json(db=g.db) else: if post.is_banned and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or post.author_id == v.id)): template = "submission_banned.html" else: template = "submission.html" @@ -361,7 +361,7 @@ def comment(v): g.db.flush() - if v.client: return c.json(g.db) + if v.client: return c.json(db=g.db) return {"comment": render_template("comments.html", v=v, comments=[c])} diff --git a/files/routes/search.py b/files/routes/search.py index 2a910a001..136d544aa 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -268,7 +268,7 @@ def searchcomments(v): comments = get_comments(ids, v=v) - if v.client: return {"total":total, "data":[x.json for x in comments]} + if v.client: return {"total":total, "data":[x.json(db=g.db) for x in comments]} return render_template("search_comments.html", v=v, query=query, total=total, page=page, comments=comments, sort=sort, t=t, next_exists=next_exists, standalone=True)