diff --git a/files/classes/submission.py b/files/classes/submission.py index 5ce8e3497..d7fb9cd7c 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -189,36 +189,6 @@ class Submission(Base): return f"/post/{self.id}/{output}" - @lazy - def rendered_page(self, sort=None, comment=None, comment_info=None, v=None): - - if self.is_banned and not (v and (v.admin_level >= 3 or self.author_id == v.id)): template = "submission_banned.html" - else: template = "submission.html" - - comments = self.__dict__.get('preloaded_comments', []) - if comments: - pinned_comment = [] - index = {} - for c in comments: - if c.is_pinned and c.parent_fullname==self.fullname: - pinned_comment += [c] - continue - if c.parent_fullname in index: index[c.parent_fullname].append(c) - else: index[c.parent_fullname] = [c] - - for c in comments: c.__dict__["replies"] = index.get(c.fullname, []) - if comment: self.__dict__["replies"] = [comment] - else: self.__dict__["replies"] = pinned_comment + index.get(self.fullname, []) - - return render_template(template, - v=v, - p=self, - sort=sort, - linked_comment=comment, - comment_info=comment_info, - render_replies=True - ) - @property @lazy def domain(self): diff --git a/files/routes/comments.py b/files/routes/comments.py index be00c9056..3f21ef7cb 100755 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -121,10 +121,13 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None): comment.is_blocked = c[3] or 0 output.append(comment) - post.preloaded_comments = output + post.replies = output if request.headers.get("Authorization"): return top_comment.json - else: return post.rendered_page(v=v, sort=sort, comment=top_comment, comment_info=comment_info) + else: + if post.is_banned and not (v and (v.admin_level >= 3 or post.author_id == v.id)): template = "submission_banned.html" + else: template = "submission.html" + return render_template(template, v=v, p=post, sort=sort, linked_comment=comment, comment_info=comment_info, render_replies=True) @app.post("/comment") diff --git a/files/routes/posts.py b/files/routes/posts.py index cf73ce7cb..a298b130b 100755 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -157,7 +157,7 @@ def post_id(pid, anything=None, v=None): comment.is_blocked = c[3] or 0 output.append(comment) - post.preloaded_comments = output + post.replies = output else: shadowbanned = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned != None).all()] @@ -174,7 +174,7 @@ def post_id(pid, anything=None, v=None): elif sort == "bottom": comments = comments.order_by(Comment.upvotes - Comment.downvotes) - post.preloaded_comments = comments.all() + post.replies = comments.all() post.views += 1 g.db.add(post) @@ -185,7 +185,10 @@ def post_id(pid, anything=None, v=None): g.db.commit() if request.headers.get("Authorization"): return post.json - else: return post.rendered_page(v=v, sort=sort) + else: + if post.is_banned and not (v and (v.admin_level >= 3 or post.author_id == v.id)): template = "submission_banned.html" + else: template = "submission.html" + return render_template(template, v=v, p=post, sort=sort, render_replies=True) @app.post("/edit_post/")