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 @@ -
Change the default sorting for comments.
Change the default sorting for posts.
Change the default time filter for posts.