diff --git a/files/classes/comment.py b/files/classes/comment.py index 0b008ca4a..a3d0279d4 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -18,17 +18,16 @@ from math import floor def sort_comments(sort, comments): if sort == 'new': - order = Comment.id.desc() + return comments.order_by(Comment.id.desc()) elif sort == 'old': - order = Comment.id + return comments.order_by(Comment.id) elif sort == 'controversial': - order = (Comment.upvotes+1)/(Comment.downvotes+1) + (Comment.downvotes+1)/(Comment.upvotes+1), Comment.downvotes.desc() + return comments.order_by((Comment.upvotes+1)/(Comment.downvotes+1) + (Comment.downvotes+1)/(Comment.upvotes+1), Comment.downvotes.desc(), Comment.id.desc()) elif sort == "bottom": - order = Comment.realupvotes + return comments.order_by(Comment.realupvotes, Comment.id.desc()) else: - order = Comment.realupvotes.desc() + return comments.order_by(Comment.realupvotes.desc(), Comment.id.desc()) - return comments.order_by(order) class Comment(Base): diff --git a/files/classes/submission.py b/files/classes/submission.py index a26624ccd..e82d769c9 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -18,19 +18,17 @@ from .votes import CommentVote def sort_posts(sort, posts): if sort == "new": - order = Submission.created_utc.desc() + return posts.order_by(Submission.created_utc.desc()) elif sort == "old": - order = Submission.created_utc + return posts.order_by(Submission.created_utc) elif sort == "controversial": - order = (Submission.upvotes+1)/(Submission.downvotes+1) + (Submission.downvotes+1)/(Submission.upvotes+1), Submission.downvotes.desc() + return posts.order_by((Submission.upvotes+1)/(Submission.downvotes+1) + (Submission.downvotes+1)/(Submission.upvotes+1), Submission.downvotes.desc(), Submission.created_utc.desc()) elif sort == "bottom": - order = Submission.realupvotes + return posts.order_by(Submission.realupvotes, Submission.created_utc.desc()) elif sort == "comments": - order = Submission.comment_count.desc() + return posts.order_by(Submission.comment_count.desc(), Submission.created_utc.desc()) else: - order = Submission.realupvotes.desc() - - return posts.order_by(order) + return posts.order_by(Submission.realupvotes.desc(), Submission.created_utc.desc()) class Submission(Base): __tablename__ = "submissions"