diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index dc923d144..a602e4f97 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -326,11 +326,33 @@ PIN_AWARD_TEXT = " (pin award)" THEMES = ["4chan","classic","classic_dark","coffee","dark","dramblr","light","midnight","tron","win98"] LIGHT_THEMES = ["4chan","classic","coffee","light","win98"] BACKGROUND_CATEGORIES = ["glitter", "anime", "fantasy", "solarpunk", "pixelart"] -COMMENT_SORTS = ["hot", "new", "old", "top", "bottom", "controversial", "random"] -SORTS = COMMENT_SORTS + ["bump", "comments", "views", "subscriptions", "saves"] -TIME_FILTERS = ["hour", "day", "week", "month", "year", "all"] PAGE_SIZES = (10, 25, 50, 100) +TIME_FILTERS = { + "hour": "clock", + "day": "calendar-day", + "week": "calendar-week", + "month": "calendar-alt", + "year": "calendar", + "all": "infinity", + } +COMMENT_SORTS = { + "hot": "fire", + "new": "sparkles", + "old": "book", + "top": "arrow-alt-circle-up", + "bottom": "arrow-alt-circle-down", + "controversial": "bullhorn", + "random": "random", + } +POST_SORTS = COMMENT_SORTS | { + "bump": "arrow-up", + "comments": "comments", + "views": "eye", + "subscriptions": "bell", + "saves": "save" + } + ################################################################################ ### COLUMN INFO ################################################################################ diff --git a/files/routes/admin.py b/files/routes/admin.py index 3ce5b80bb..ce6fd08fc 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1358,7 +1358,7 @@ def remove_post(post_id, v): v.pay_account('coins', 1) g.db.add(v) - for sort in COMMENT_SORTS: + for sort in COMMENT_SORTS.keys(): cache.delete(f'post_{post.id}_{sort}') return {"message": "Post removed!"} @@ -1395,7 +1395,7 @@ def approve_post(post_id, v): v.charge_account('coins', 1) g.db.add(v) - for sort in COMMENT_SORTS: + for sort in COMMENT_SORTS.keys(): cache.delete(f'post_{post.id}_{sort}') return {"message": "Post approved!"} @@ -1606,7 +1606,7 @@ def remove_comment(c_id, v): g.db.add(ma) if comment.parent_post: - for sort in COMMENT_SORTS: + for sort in COMMENT_SORTS.keys(): cache.delete(f'post_{comment.parent_post}_{sort}') return {"message": "Comment removed!"} @@ -1639,7 +1639,7 @@ def approve_comment(c_id, v): g.db.add(comment) if comment.parent_post: - for sort in COMMENT_SORTS: + for sort in COMMENT_SORTS.keys(): cache.delete(f'post_{comment.parent_post}_{sort}') return {"message": "Comment approved!"} diff --git a/files/routes/comments.py b/files/routes/comments.py index b02e99855..08a73966b 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -415,7 +415,7 @@ def comment(v): g.db.flush() if c.parent_post: - for sort in COMMENT_SORTS: + for sort in COMMENT_SORTS.keys(): cache.delete(f'post_{c.parent_post}_{sort}') if v.client: return c.json @@ -444,7 +444,7 @@ def delete_comment(cid, v): cache.delete_memoized(comment_idlist) if c.parent_post: - for sort in COMMENT_SORTS: + for sort in COMMENT_SORTS.keys(): cache.delete(f'post_{c.parent_post}_{sort}') return {"message": "Comment deleted!"} @@ -469,7 +469,7 @@ def undelete_comment(cid, v): cache.delete_memoized(comment_idlist) if c.parent_post: - for sort in COMMENT_SORTS: + for sort in COMMENT_SORTS.keys(): cache.delete(f'post_{c.parent_post}_{sort}') return {"message": "Comment undeleted!"} diff --git a/files/routes/jinja2.py b/files/routes/jinja2.py index 8bf4ea4c3..eff54f45a 100644 --- a/files/routes/jinja2.py +++ b/files/routes/jinja2.py @@ -41,12 +41,11 @@ def post_embed(id, v): def template_asset(ctx, asset_path): return assetcache_path(asset_path) - -@app.template_filter("change_page") -def template_change_page(new_page, url): +@app.template_filter("change_arg") +def template_change_arg(arg, value, url): parsed = urlsplit(url) query_dict = parse_qs(parsed.query) - query_dict["page"] = new_page + query_dict[arg] = value query_new = urlencode(query_dict, doseq=True) parsed = parsed._replace(query=query_new) return parsed.geturl() @@ -119,7 +118,7 @@ def inject_constants(): "TELEGRAM_ID":TELEGRAM_ID, "TRUESCORE_DONATE_MINIMUM":TRUESCORE_DONATE_MINIMUM, "PROGSTACK_ID":PROGSTACK_ID, "DONATE_LINK":DONATE_LINK, "DONATE_SERVICE":DONATE_SERVICE, "HOUSE_JOIN_COST":HOUSE_JOIN_COST, "HOUSE_SWITCH_COST":HOUSE_SWITCH_COST, "IMAGE_FORMATS":','.join(IMAGE_FORMATS), - "PAGE_SIZES":PAGE_SIZES, "THEMES":THEMES, "COMMENT_SORTS":COMMENT_SORTS, "SORTS":SORTS, + "PAGE_SIZES":PAGE_SIZES, "THEMES":THEMES, "COMMENT_SORTS":COMMENT_SORTS, "POST_SORTS":POST_SORTS, "TIME_FILTERS":TIME_FILTERS, "HOUSES":HOUSES, "TIER_TO_NAME":TIER_TO_NAME, "DEFAULT_CONFIG_VALUE":DEFAULT_CONFIG_VALUE, "IS_LOCALHOST":IS_LOCALHOST, "BACKGROUND_CATEGORIES":BACKGROUND_CATEGORIES, "PAGE_SIZE":PAGE_SIZE, "TAGLINES":TAGLINES, "get_alt_graph":get_alt_graph, "current_registered_users":current_registered_users, "git_head":git_head, "max_days":max_days, "EMOJI_KINDS":EMOJI_KINDS, diff --git a/files/routes/posts.py b/files/routes/posts.py index a3e52bb83..f9d0c4b59 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -706,7 +706,7 @@ def delete_post_pid(pid, v): v.post_count -= 1 g.db.add(v) - for sort in COMMENT_SORTS: + for sort in COMMENT_SORTS.keys(): cache.delete(f'post_{p.id}_{sort}') return {"message": "Post deleted!"} @@ -731,7 +731,7 @@ def undelete_post_pid(pid, v): v.post_count += 1 g.db.add(v) - for sort in COMMENT_SORTS: + for sort in COMMENT_SORTS.keys(): cache.delete(f'post_{p.id}_{sort}') return {"message": "Post undeleted!"} diff --git a/files/routes/settings.py b/files/routes/settings.py index 79070665a..800ffb25a 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -120,7 +120,7 @@ def settings_personal_post(v): opt = request.values.get(api_name) if opt: opt = opt.strip() if not opt: return False - if opt in valid_values: + if opt in valid_values.keys(): setattr(v, column_name, opt) return True abort(400, f"'{opt}' is not a valid {error_msg}") @@ -316,7 +316,7 @@ def settings_personal_post(v): else: abort(400) updated = updated or set_selector_option("defaultsortingcomments", "defaultsortingcomments", COMMENT_SORTS, "comment sort") - updated = updated or set_selector_option("defaultsorting", "defaultsorting", SORTS, "post sort") + updated = updated or set_selector_option("defaultsorting", "defaultsorting", POST_SORTS, "post sort") updated = updated or set_selector_option("defaulttime", "defaulttime", TIME_FILTERS, "time filter") theme = request.values.get("theme") diff --git a/files/templates/home.html b/files/templates/home.html index c6b9f6624..92d690c31 100644 --- a/files/templates/home.html +++ b/files/templates/home.html @@ -81,58 +81,9 @@ - - - + {%- import 'util/macros.html' as macros with context -%} + {{- macros.time_filter_buttons() -}} + {{- macros.sorting_buttons(POST_SORTS) -}} {% endblock %} diff --git a/files/templates/home_comments.html b/files/templates/home_comments.html index 09736cf94..47bc03d49 100644 --- a/files/templates/home_comments.html +++ b/files/templates/home_comments.html @@ -6,50 +6,10 @@ {% block content %}
-
- - - + {%- import 'util/macros.html' as macros with context -%} + {{- macros.time_filter_buttons() -}} + {{- macros.sorting_buttons(COMMENT_SORTS) -}}
diff --git a/files/templates/pagination.html b/files/templates/pagination.html index d062fe690..6530ebebe 100644 --- a/files/templates/pagination.html +++ b/files/templates/pagination.html @@ -26,12 +26,12 @@ {% if ns.start_point > 1 %}
  • - 1 + 1
  • {% if ns.start_point == 3 %}
  • - 2 + 2
  • {% elif ns.start_point != 2 %}
  • @@ -43,14 +43,14 @@ {% for x in range(ns.start_point, end_point+1) %}
  • - {{x}} + {{x}}
  • {% endfor %} {% if end_point < num_pages %} {% if end_point == num_pages-2 %}
  • - {{num_pages-1}} + {{num_pages-1}}
  • {% elif end_point != num_pages-1 %}
  • @@ -59,7 +59,7 @@ {% endif %}
  • - {{num_pages}} + {{num_pages}}
  • {% endif %} diff --git a/files/templates/post.html b/files/templates/post.html index 2dc137773..b6979a23e 100644 --- a/files/templates/post.html +++ b/files/templates/post.html @@ -284,27 +284,8 @@
    - + {%- import 'util/macros.html' as macros with context -%} + {{- macros.sorting_buttons(COMMENT_SORTS) -}}
    {{macros.comment_reply_box(p.fullname, 'comment-reply-' + p.fullname, subwrapper_css_classes='mb-3', enable_cancel_button=false)}} diff --git a/files/templates/post_banned.html b/files/templates/post_banned.html index 289c2f55e..066652d87 100644 --- a/files/templates/post_banned.html +++ b/files/templates/post_banned.html @@ -58,27 +58,8 @@
    - + {%- import 'util/macros.html' as macros with context -%} + {{- macros.sorting_buttons(COMMENT_SORTS) -}}
    diff --git a/files/templates/search.html b/files/templates/search.html index 9885f8366..83bf0d606 100644 --- a/files/templates/search.html +++ b/files/templates/search.html @@ -95,54 +95,13 @@ {% if not '/users' in request.path %}
    - - - + {%- import 'util/macros.html' as macros with context -%} + {{- macros.time_filter_buttons() -}} + {% if "/posts" in request.path %} + {{- macros.sorting_buttons(POST_SORTS) -}} + {% else %} + {{- macros.sorting_buttons(COMMENT_SORTS) -}} + {% endif %}
    {% endif %}
    diff --git a/files/templates/settings/advanced.html b/files/templates/settings/advanced.html index 697307a9e..919eb2d1b 100644 --- a/files/templates/settings/advanced.html +++ b/files/templates/settings/advanced.html @@ -56,7 +56,7 @@

    Change the default sorting for comments.

    @@ -71,7 +71,7 @@

    Change the default sorting for posts.

    @@ -86,7 +86,7 @@

    Change the default time filter for posts.

    diff --git a/files/templates/userpage/header.html b/files/templates/userpage/header.html index c099c1fd2..29f14ce65 100644 --- a/files/templates/userpage/header.html +++ b/files/templates/userpage/header.html @@ -31,48 +31,13 @@
    - - - + {%- import 'util/macros.html' as macros with context -%} + {{- macros.time_filter_buttons() -}} + {% if "/posts" in request.path %} + {{- macros.sorting_buttons(POST_SORTS) -}} + {% else %} + {{- macros.sorting_buttons(COMMENT_SORTS) -}} + {% endif %}
    {% endif %} diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index 31b0ee4a8..f284b6d2c 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -350,3 +350,41 @@
    {% endmacro %} + +{% macro time_filter_buttons() %} + +{% endmacro %} + +{% macro sorting_buttons(sorts) %} + +{% endmacro %}