diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index ae0571115..0f8f5839d 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -400,7 +400,7 @@ PIN_AWARD_TEXT = " (pin award)" THEMES = ["4chan","classic","classic_dark","coffee","dark","dramblr","light","midnight","tron","win98"] BACKGROUND_CATEGORIES = ["glitter", "anime", "fantasy", "solarpunk", "pixelart"] COMMENT_SORTS = ["hot", "new", "old", "top", "bottom", "controversial"] -SORTS = COMMENT_SORTS + ["bump", "comments", "views"] +SORTS = COMMENT_SORTS + ["bump", "comments", "views", "subscriptionbs", "saves"] TIME_FILTERS = ["hour", "day", "week", "month", "year", "all"] PAGE_SIZES = (10, 25, 50, 100) diff --git a/files/helpers/sorting_and_time.py b/files/helpers/sorting_and_time.py index 766f4e978..36ac7dca7 100644 --- a/files/helpers/sorting_and_time.py +++ b/files/helpers/sorting_and_time.py @@ -5,6 +5,9 @@ from sqlalchemy.sql import func from files.helpers.config.const import * +from files.classes.subscriptions import Subscription +from files.classes.saves import * + def apply_time_filter(t, objects, cls): now = int(time.time()) if t == 'hour': @@ -34,6 +37,12 @@ def sort_objects(sort, objects, cls): return objects.filter(cls.comment_count > 1).order_by(cls.bump_utc.desc(), cls.created_utc.desc()) elif sort == "comments" and cls.__name__ == "Submission": return objects.order_by(cls.comment_count.desc(), cls.created_utc.desc()) + elif sort == "subscriptions" and cls.__name__ == "Submission": + return objects.outerjoin(Subscription).group_by(cls.id).order_by(func.count(Subscription.submission_id).desc(), cls.created_utc.desc()) + elif sort == "saves" and cls.__name__ == "Submission": + return objects.outerjoin(SaveRelationship).group_by(cls.id).order_by(func.count(SaveRelationship.submission_id).desc(), cls.created_utc.desc()) + elif sort == "saves" and cls.__name__ == "Comment": + return objects.outerjoin(CommentSaveRelationship).group_by(cls.id).order_by(func.count(CommentSaveRelationship.comment_id).desc(), cls.created_utc.desc()) elif sort == "new": return objects.order_by(cls.created_utc.desc()) elif sort == "old": diff --git a/files/templates/home.html b/files/templates/home.html index d763e98ca..53326f2cb 100644 --- a/files/templates/home.html +++ b/files/templates/home.html @@ -118,6 +118,8 @@ {% if sort=="old" %}{% endif %} {% if sort=="controversial" %}{% endif %} {% if sort=="comments" %}{% endif %} + {% if sort=="subscriptions" %}{% endif %} + {% if sort=="saves" %}{% endif %} {{sort | capitalize}} diff --git a/files/templates/home_comments.html b/files/templates/home_comments.html index 31640a432..8b52f1083 100644 --- a/files/templates/home_comments.html +++ b/files/templates/home_comments.html @@ -36,6 +36,7 @@ {% if sort=="new" %}{% endif %} {% if sort=="old" %}{% endif %} {% if sort=="controversial" %}{% endif %} + {% if sort=="saves" %}{% endif %} {{sort | capitalize}} diff --git a/files/templates/post_actions.html b/files/templates/post_actions.html index 1ca195c4f..ef712534c 100644 --- a/files/templates/post_actions.html +++ b/files/templates/post_actions.html @@ -17,8 +17,8 @@ {% if v %} - - + + diff --git a/files/templates/post_actions_mobile.html b/files/templates/post_actions_mobile.html index 834b247c3..5b48b44aa 100644 --- a/files/templates/post_actions_mobile.html +++ b/files/templates/post_actions_mobile.html @@ -20,9 +20,9 @@ {%- endif %} - + - + diff --git a/files/templates/search.html b/files/templates/search.html index 493ce75b0..a2085e483 100644 --- a/files/templates/search.html +++ b/files/templates/search.html @@ -120,6 +120,8 @@ {% if sort=="old" %}{% endif %} {% if sort=="controversial" %}{% endif %} {% if sort=="comments" %}{% endif %} + {% if sort=="subscriptions" %}{% endif %} + {% if sort=="saves" %}{% endif %} {{sort | capitalize}}