diff --git a/files/classes/comment.py b/files/classes/comment.py index 2c0b53962..56fa48584 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -296,16 +296,6 @@ class Comment(Base): return data - @property - @lazy - def is_blocking(self): - return self.__dict__.get('_is_blocking', 0) - - @property - @lazy - def is_blocked(self): - return self.__dict__.get('_is_blocked', 0) - @property def body(self): if self.comment_aux: return self.comment_aux.body diff --git a/files/classes/submission.py b/files/classes/submission.py index 157bcd776..8b50b73c2 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -212,19 +212,10 @@ class Submission(Base): @lazy def rendered_page(self, sort=None, last_view_utc=None, comment=None, comment_info=None, v=None): - # check for banned - if v and (v.admin_level >= 3 or self.author_id == v.id): - template = "submission.html" - elif self.is_banned: - template = "submission_banned.html" - else: - template = "submission.html" + 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" - # load and tree comments - # calling this function with a comment object will do a comment - # permalink thing - if "replies" not in self.__dict__ and "preloaded_comments" in self.__dict__: - self.tree_comments(comment=comment) + self.tree_comments(comment=comment) return render_template(template, v=v, @@ -233,7 +224,6 @@ class Submission(Base): sort=sort, linked_comment=comment, comment_info=comment_info, - render_replies=True, ) @property @@ -247,9 +237,8 @@ class Submission(Base): def tree_comments(self, comment=None, v=None): - comments = self.__dict__.get('preloaded_comments',[]) - if not comments: - return + comments = self.__dict__.get('preloaded_comments', []) + if not comments: return pinned_comment=[] @@ -257,21 +246,16 @@ class Submission(Base): for c in comments: if c.is_pinned and c.parent_fullname==self.fullname: - pinned_comment+=[c] + pinned_comment += [c] continue - if c.parent_fullname in index: - index[c.parent_fullname].append(c) - else: - index[c.parent_fullname] = [c] + 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, []) + 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, []) + if comment: self.__dict__["replies"] = [comment] + else: self.__dict__["replies"] = pinned_comment + index.get(self.fullname, []) @property @lazy @@ -468,20 +452,6 @@ class Submission(Base): self.submission_aux.embed_url = x g.db.add(self.submission_aux) - @property - @lazy - def is_blocked(self): - return self.__dict__.get('_is_blocked', False) - - @property - @lazy - def is_blocking(self): - return self.__dict__.get('_is_blocking', False) - - #@property - #def award_count(self): - #return len(self.awards) - @property @lazy def is_image(self): diff --git a/files/classes/user.py b/files/classes/user.py index 976704d79..b128212a8 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -533,16 +533,6 @@ class User(Base): def is_suspended(self): return (self.is_banned and (not self.unban_utc or self.unban_utc > time.time())) - @property - @lazy - def is_blocking(self): - return self.__dict__.get('_is_blocking', 0) - - @property - @lazy - def is_blocked(self): - return self.__dict__.get('_is_blocked', 0) - @property @lazy diff --git a/files/helpers/get.py b/files/helpers/get.py index c0ecd46c8..ae34f900f 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -36,8 +36,8 @@ def get_user(username, v=None, graceful=False): ) ).first() - user._is_blocking = block and block.user_id == v.id - user._is_blocked = block and block.target_id == v.id + user.is_blocking = block and block.user_id == v.id + user.is_blocked = block and block.target_id == v.id return user @@ -64,8 +64,8 @@ def get_account(id, v=None): ) ).first() - user._is_blocking = block and block.user_id == v.id - user._is_blocked = block and block.target_id == v.id + user.is_blocking = block and block.user_id == v.id + user.is_blocked = block and block.target_id == v.id return user @@ -102,7 +102,7 @@ def get_post(i, v=None, graceful=False, **kwargs): abort(404) x = items[0] x.voted = items[1] or 0 - x._is_blocking = items[2] or 0 + x.is_blocking = items[2] or 0 else: items = g.db.query( Submission @@ -152,8 +152,8 @@ def get_posts(pids, v=None): output = [p[0] for p in query] for i in range(len(output)): output[i].voted = query[i][1] or 0 - output[i]._is_blocking = query[i][2] or 0 - output[i]._is_blocked = query[i][3] or 0 + output[i].is_blocking = query[i][2] or 0 + output[i].is_blocked = query[i][3] or 0 else: output = g.db.query(Submission,).options(lazyload('*')).filter(Submission.id.in_(pids)).all() @@ -181,8 +181,8 @@ def get_comment(i, v=None, graceful=False, **kwargs): vts = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id, comment_id=comment.id) vt = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id, comment_id=comment.id).first() - comment._is_blocking = block and block.user_id == v.id - comment._is_blocked = block and block.target_id == v.id + comment.is_blocking = block and block.user_id == v.id + comment.is_blocked = block and block.target_id == v.id comment.voted = vt.vote_type if vt else 0 else: @@ -233,8 +233,8 @@ def get_comments(cids, v=None, load_parent=False): for c in comments: comment = c[0] comment.voted = c[1] or 0 - comment._is_blocking = c[2] or 0 - comment._is_blocked = c[3] or 0 + comment.is_blocking = c[2] or 0 + comment.is_blocked = c[3] or 0 output.append(comment) else: diff --git a/files/routes/admin.py b/files/routes/admin.py index c0a65ba80..c75894742 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1156,7 +1156,6 @@ def admin_distinguish_comment(c_id, v): "comments.html", v=v, comments=[comment], - render_replies=False, ) html=str(BeautifulSoup(html, features="html.parser").find(id=f"comment-{comment.id}-only")) diff --git a/files/routes/comments.py b/files/routes/comments.py index 14ed60686..d9e06fad2 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -55,20 +55,12 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None): if request.headers.get("Authorization"): return {'error': f'This content is not suitable for some users and situations.'} else: render_template("errors/nsfw.html", v=v) - post._preloaded_comments = [comment] - - # context improver try: context = int(request.values.get("context", 0)) except: context = 0 comment_info = comment c = comment while context > 0 and c.level > 1: - - parent = get_comment(c.parent_comment_id, v=v) - - post._preloaded_comments += [parent] - - c = parent + c = c.parent_comment context -= 1 top_comment = c @@ -114,12 +106,16 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None): isouter=True ) + output = [] for c in comments: comment = c[0] comment.voted = c[1] or 0 - comment._is_blocking = c[2] or 0 - comment._is_blocked = c[3] or 0 + comment.is_blocking = c[2] or 0 + comment.is_blocked = c[3] or 0 + output.append(comment) + post.preloaded_comments = 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) @@ -593,7 +589,6 @@ def api_comment(v): else: return jsonify({"html": render_template("comments.html", v=v, comments=[c], - render_replies=False, )}) diff --git a/files/routes/front.py b/files/routes/front.py index 2e437cb7c..c115c502f 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -72,8 +72,8 @@ def notifications(v): if not posts: listing = [] for c in comments: - c._is_blocked = False - c._is_blocking = False + c.is_blocked = False + c.is_blocking = False if c.parent_submission and c.parent_comment and c.parent_comment.author_id == v.id: c.replies = [] while c.parent_comment and c.parent_comment.author_id == v.id: @@ -104,7 +104,6 @@ def notifications(v): next_exists=next_exists, page=page, standalone=True, - render_replies=True, is_notification_page=True) diff --git a/files/routes/posts.py b/files/routes/posts.py index 093aa5a73..2a80cbfcb 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -167,8 +167,8 @@ def post_id(pid, anything=None, v=None): for c in comments: comment = c[0] comment.voted = c[1] or 0 - comment._is_blocking = c[2] or 0 - comment._is_blocked = c[3] or 0 + comment.is_blocking = c[2] or 0 + comment.is_blocked = c[3] or 0 output.append(comment) post.preloaded_comments = output diff --git a/files/routes/users.py b/files/routes/users.py index f559a8d90..812813b84 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -295,7 +295,6 @@ def messagereply(v): return jsonify({"html": render_template("comments.html", v=v, comments=[new_comment], - render_replies=False, )}) @app.get("/2faqr/") diff --git a/files/templates/comments.html b/files/templates/comments.html index 7270e4519..59001d274 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -65,26 +65,24 @@ - {% if render_replies %} - {% if level<7 %} -
- {% set standalone=False %} - {% for reply in replies %} - {{single_comment(reply, level=level+1)}} - {% endfor %} -
- {% elif replies %} -
- {% set standalone=False %} - {% for reply in replies %} - {{single_comment(reply, level=level+1)}} - {% endfor %} -
-
- More comments -
- {% endif %} - {% endif %} + {% if level<7 %} +
+ {% set standalone=False %} + {% for reply in replies %} + {{single_comment(reply, level=level+1)}} + {% endfor %} +
+ {% elif replies %} +
+ {% set standalone=False %} + {% for reply in replies %} + {{single_comment(reply, level=level+1)}} + {% endfor %} +
+
+ More comments +
+ {% endif %} @@ -417,23 +415,21 @@ - {% if render_replies %} - {% if level<7 %} -
- {% for reply in replies %} - {{single_comment(reply, level=level+1)}} - {% endfor %} -
- {% elif replies %} -
- {% for reply in replies %} - {{single_comment(reply, level=level+1)}} - {% endfor %} -
-
- More comments -
- {% endif %} + {% if level<7 %} +
+ {% for reply in replies %} + {{single_comment(reply, level=level+1)}} + {% endfor %} +
+ {% elif replies %} +
+ {% for reply in replies %} + {{single_comment(reply, level=level+1)}} + {% endfor %} +
+
+ More comments +
{% endif %}