diff --git a/files/classes/comment.py b/files/classes/comment.py index e77cf97e2..fa2ae8f9e 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -194,12 +194,9 @@ class Comment(Base): @property @lazy def parent(self): - if not self.parent_submission: return None - if self.level == 1: return self.post - - else: return g.db.query(Comment).get(self.parent_comment_id) + else: return g.db.get(Comment, self.parent_comment_id) @property @lazy diff --git a/files/helpers/comments.py b/files/helpers/comments.py index cab2925d5..5e04a336e 100644 --- a/files/helpers/comments.py +++ b/files/helpers/comments.py @@ -141,13 +141,13 @@ def bulk_recompute_descendant_counts(predicate = None, db=None): True ) .group_by(parent_comments.corresponding_column(Comment.id)) - .with_only_columns([ + .with_only_columns( parent_comments.corresponding_column(Comment.id), func.coalesce( func.sum(child_comments.corresponding_column(Comment.descendant_count) + text(str(1))), text(str(0)) ).label('descendant_count') - ]) + ) .subquery(name='descendant_counts') ), adapt_on_names=True diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index 533582aa7..f61bb0b42 100644 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -25,7 +25,7 @@ def get_logged_in_user(): lo_user = session.get("lo_user") if lo_user: id = int(lo_user) - v = g.db.query(User).get(id) + v = g.db.get(User, id) if v: v.client = None nonce = session.get("login_nonce", 0) diff --git a/files/routes/admin.py b/files/routes/admin.py index f882e116a..22c58c52a 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -273,12 +273,12 @@ def update_filter_status(v): return { 'result': f'Status of {new_status} is not permitted' } if post_id: - p = g.db.query(Submission).get(post_id) + p = g.db.get(Submission, post_id) old_status = p.filter_state rows_updated = g.db.query(Submission).where(Submission.id == post_id) \ .update({Submission.filter_state: new_status}) elif comment_id: - c = g.db.query(Comment).get(comment_id) + c = g.db.get(Comment, comment_id) old_status = c.filter_state rows_updated = g.db.query(Comment).where(Comment.id == comment_id) \ .update({Comment.filter_state: new_status}) @@ -732,13 +732,12 @@ def alt_votes_get(v): @limiter.exempt @admin_level_required(2) def admin_link_accounts(v): - - u1 = int(request.values.get("u1")) - u2 = int(request.values.get("u2")) + u1 = get_account(request.values.get("u1", '')) + u2 = get_account(request.values.get("u2", '')) new_alt = Alt( - user1=u1, - user2=u2, + user1=u1.id, + user2=u2.id, is_manual=True ) @@ -753,7 +752,7 @@ def admin_link_accounts(v): g.db.add(ma) g.db.commit() - return redirect(f"/admin/alt_votes?u1={g.db.query(User).get(u1).username}&u2={g.db.query(User).get(u2).username}") + return redirect(f"/admin/alt_votes?u1={u1.id}&u2={u2.id}") @app.get("/admin/removed/posts")