From e15bddfc9e7d3ba3d3c91df25ebb95cdc23c6fe8 Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 27 Apr 2023 16:30:35 +0200 Subject: [PATCH] add "views" sort --- files/helpers/config/const.py | 2 +- files/helpers/sorting_and_time.py | 2 + files/templates/home.html | 62 ++++++++++++++++--------------- files/templates/search.html | 6 ++- 4 files changed, 39 insertions(+), 33 deletions(-) diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index eb43eeada7..bacd7a1bb3 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -399,7 +399,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"] +SORTS = COMMENT_SORTS + ["bump", "comments", "views"] 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 065d283d96..766f4e9788 100644 --- a/files/helpers/sorting_and_time.py +++ b/files/helpers/sorting_and_time.py @@ -28,6 +28,8 @@ def sort_objects(sort, objects, cls): metric = cls.realupvotes if cls.__name__ == "Submission": metric += cls.comment_count/5 return objects.order_by(-1000000*(metric + 1)/(func.power(((ti - cls.created_utc)/1000), 1.23)), cls.created_utc.desc()) + elif sort == "views" and cls.__name__ == "Submission": + return objects.order_by(cls.views.desc(), cls.created_utc.desc()) elif sort == "bump" and cls.__name__ == "Submission": return objects.filter(cls.comment_count > 1).order_by(cls.bump_utc.desc(), cls.created_utc.desc()) elif sort == "comments" and cls.__name__ == "Submission": diff --git a/files/templates/home.html b/files/templates/home.html index e6c79af57c..d763e98ca6 100644 --- a/files/templates/home.html +++ b/files/templates/home.html @@ -79,55 +79,57 @@ {% if SITE_NAME != 'WPD' and not sub %} {% set hcolor = "primary" if holes else "secondary" %} - Holes + Holes {% endif %} {% set pcolor = "primary" if pins else "secondary" %} - Pins + Pins diff --git a/files/templates/search.html b/files/templates/search.html index 42c3dbce9e..7ce3a249ab 100644 --- a/files/templates/search.html +++ b/files/templates/search.html @@ -90,7 +90,7 @@ {% if not '/users' in request.path %}
- -