forked from rDrama/rDrama
yolo
parent
53b86c9918
commit
cc35cd3633
|
@ -189,36 +189,6 @@ class Submission(Base):
|
||||||
|
|
||||||
return f"/post/{self.id}/{output}"
|
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
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def domain(self):
|
def domain(self):
|
||||||
|
|
|
@ -121,10 +121,13 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
|
||||||
comment.is_blocked = c[3] or 0
|
comment.is_blocked = c[3] or 0
|
||||||
output.append(comment)
|
output.append(comment)
|
||||||
|
|
||||||
post.preloaded_comments = output
|
post.replies = output
|
||||||
|
|
||||||
if request.headers.get("Authorization"): return top_comment.json
|
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")
|
@app.post("/comment")
|
||||||
|
|
|
@ -157,7 +157,7 @@ def post_id(pid, anything=None, v=None):
|
||||||
comment.is_blocked = c[3] or 0
|
comment.is_blocked = c[3] or 0
|
||||||
output.append(comment)
|
output.append(comment)
|
||||||
|
|
||||||
post.preloaded_comments = output
|
post.replies = output
|
||||||
|
|
||||||
else:
|
else:
|
||||||
shadowbanned = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned != None).all()]
|
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":
|
elif sort == "bottom":
|
||||||
comments = comments.order_by(Comment.upvotes - Comment.downvotes)
|
comments = comments.order_by(Comment.upvotes - Comment.downvotes)
|
||||||
|
|
||||||
post.preloaded_comments = comments.all()
|
post.replies = comments.all()
|
||||||
|
|
||||||
post.views += 1
|
post.views += 1
|
||||||
g.db.add(post)
|
g.db.add(post)
|
||||||
|
@ -185,7 +185,10 @@ def post_id(pid, anything=None, v=None):
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
if request.headers.get("Authorization"): return post.json
|
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/<pid>")
|
@app.post("/edit_post/<pid>")
|
||||||
|
|
Loading…
Reference in New Issue