aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--apioforum/forum.py13
-rw-r--r--apioforum/static/style.css3
-rw-r--r--apioforum/templates/view_forum.html24
3 files changed, 33 insertions, 7 deletions
diff --git a/apioforum/forum.py b/apioforum/forum.py
index 305cb51..bf9610d 100644
--- a/apioforum/forum.py
+++ b/apioforum/forum.py
@@ -96,8 +96,16 @@ def view_forum(forum,page=1):
if page < 1:
abort(400)
db = get_db()
+
+ sortby = request.args.get("sortby","ad")
+ try:
+ sortby_dir = {'d':'DESC','a':'ASC'}[sortby[1]]
+ sortby_by = {'a':'threads.updated','c':'threads.created'}[sortby[0]]
+ except KeyError:
+ return redirect(url_for('forum.view_forum',forum_id=forum_id))
+
threads = db.execute(
- """SELECT
+ f"""SELECT
threads.id, threads.title, threads.creator, threads.created,
threads.updated, threads.poll, number_of_posts.num_replies,
most_recent_posts.created as mrp_created,
@@ -109,7 +117,7 @@ def view_forum(forum,page=1):
INNER JOIN most_recent_posts ON most_recent_posts.thread = threads.id
INNER JOIN number_of_posts ON number_of_posts.thread = threads.id
WHERE threads.forum = ?
- ORDER BY threads.updated DESC
+ ORDER BY {sortby_by} {sortby_dir}
LIMIT ? OFFSET ?;
""",(
forum['id'],
@@ -190,6 +198,7 @@ def view_forum(forum,page=1):
avail_tags=avail_tags,
max_pageno=max_pageno,
page=page,
+ current_sortby=sortby
)
@forum_route("create_thread",methods=("GET","POST"))
diff --git a/apioforum/static/style.css b/apioforum/static/style.css
index d50c7b0..cd275ff 100644
--- a/apioforum/static/style.css
+++ b/apioforum/static/style.css
@@ -291,4 +291,5 @@ fieldset { margin-bottom: 15px; }
content: "/\00a0";
padding: 8px;
}
-
+
+
diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html
index 649c87c..c1906b6 100644
--- a/apioforum/templates/view_forum.html
+++ b/apioforum/templates/view_forum.html
@@ -83,7 +83,26 @@ please log in to create a new thread
you do not have permission to create threads in this forum
{% endif %}
-{% if has_permission(forum.id, g.user, "p_view_threads", login_required=False) %}
+{% macro sortby_option(code, text) %}
+{% if current_sortby==code %}
+<option selected value="{{code}}">{{text}}</option>
+{% else %}
+<option value="{{code}}">{{text}}</option>
+{% endif %}
+{% endmacro %}
+
+<form class="inline-form small-form" method="get">
+ <label for="sortby">sort threads by</label>
+ <select name="sortby">
+ {{ sortby_option("ad", "last activity (newest first)") }}
+ {{ sortby_option("aa", "last activity (oldest first)") }}
+ {{ sortby_option("cd", "creation time (newest first)") }}
+ {{ sortby_option("ca", "creation time (oldest first)") }}
+ </select>
+ <input type="submit" value="go">
+</form>
+</p>
+
{{ pagination_nav(page,max_pageno,'forum.view_forum',forum_id=forum.id) }}
<div class="thread-list">
{%for thread in threads%}
@@ -136,7 +155,4 @@ you do not have permission to create threads in this forum
</div>
-{% else %}
-<p>you do not have permission to view threads in this forum</p>
-{% endif %}
{%endblock%}