Jinja2: add SORTS_COMMON and SORTS_ALL

This commit is contained in:
justcool393 2023-02-16 18:27:16 -06:00
parent 384b4fbd22
commit ba96decb9b
4 changed files with 5 additions and 3 deletions

View file

@ -86,6 +86,8 @@ def inject_constants():
"PERMS":PERMS, "PERMS":PERMS,
"FEATURES":FEATURES, "FEATURES":FEATURES,
"RENDER_DEPTH_LIMIT":RENDER_DEPTH_LIMIT, "RENDER_DEPTH_LIMIT":RENDER_DEPTH_LIMIT,
"SORTS_COMMON":SORTS_COMMON,
"SORTS_POSTS":SORTS_POSTS,
} }

View file

@ -215,7 +215,7 @@ def settings_profile_post(v):
defaultsortingcomments = request.values.get("defaultsortingcomments") defaultsortingcomments = request.values.get("defaultsortingcomments")
if defaultsortingcomments: if defaultsortingcomments:
if defaultsortingcomments in SORTS_ALL: if defaultsortingcomments in SORTS_COMMON:
v.defaultsortingcomments = defaultsortingcomments v.defaultsortingcomments = defaultsortingcomments
updated = True updated = True
else: abort(400) else: abort(400)

View file

@ -3,7 +3,7 @@
<button class="btn btn-secondary dropdown-toggle" role="button" id="dropdownMenuButton2" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <button class="btn btn-secondary dropdown-toggle" role="button" id="dropdownMenuButton2" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas {{SORTS_POSTS[sort]}} mr-1"></i> {{sort|capitalize}} <i class="fas {{SORTS_POSTS[sort]}} mr-1"></i> {{sort|capitalize}}
</button> </button>
{% for possible_sort in (SORTS_ALL if is_comment else SORTS_POSTS) %} {% for possible_sort in (SORTS_COMMON if is_comment else SORTS_POSTS) %}
{%- if sort != possible_sort -%} {%- if sort != possible_sort -%}
<a class="dropdown-item" href="?{{extra_query ~ '&' if extra_query else ''}}sort={{possible_sort}}&t={{t}}"><i class="fas {{SORTS_POSTS[possible_sort]}} mr-1"></i> {{possible_sort | capitalize}}</a> <a class="dropdown-item" href="?{{extra_query ~ '&' if extra_query else ''}}sort={{possible_sort}}&t={{t}}"><i class="fas {{SORTS_POSTS[possible_sort]}} mr-1"></i> {{possible_sort | capitalize}}</a>
{%- endif -%} {%- endif -%}

View file

@ -37,7 +37,7 @@
<p>Change the default sorting for comments.</p> <p>Change the default sorting for comments.</p>
<div class="input-group mb2"> <div class="input-group mb2">
<select autocomplete="off" id='defaultsortingcomments' class="form-control" form="profile-settings" name="defaultsortingcomments" onchange="post_toast(this,'/settings/profile?defaultsortingcomments='+document.getElementById('defaultsortingcomments').value)"> <select autocomplete="off" id='defaultsortingcomments' class="form-control" form="profile-settings" name="defaultsortingcomments" onchange="post_toast(this,'/settings/profile?defaultsortingcomments='+document.getElementById('defaultsortingcomments').value)">
{% for entry in SORTS_ALL %} {% for entry in SORTS_COMMON %}
<option value="{{entry}}"{{' selected' if v.defaultsortingcomments==entry}}>{{entry}}</option> <option value="{{entry}}"{{' selected' if v.defaultsortingcomments==entry}}>{{entry}}</option>
{% endfor %} {% endfor %}
</select> </select>