summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorubq323 <ubq323>2021-07-22 18:35:01 +0000
committerubq323 <ubq323>2021-07-22 18:35:01 +0000
commit87dbc43d138cdd21f64a0e87d1010f86095eadb3 (patch)
tree03f6144e87f86a58387b93aa72d90e72efed637a
parent74a992ca018a69cc1de6225a681ca17c19c74ffa (diff)
add 'sort threads by' thing, ui styling is very bad atmthread-filtering
-rw-r--r--apioforum/forum.py12
-rw-r--r--apioforum/static/style.css3
-rw-r--r--apioforum/templates/view_forum.html10
3 files changed, 21 insertions, 4 deletions
diff --git a/apioforum/forum.py b/apioforum/forum.py
index e03ca01..a0ec968 100644
--- a/apioforum/forum.py
+++ b/apioforum/forum.py
@@ -3,7 +3,7 @@
from flask import (
Blueprint, render_template, request,
- g, redirect, url_for, flash
+ g, redirect, url_for, flash, abort
)
from .db import get_db
@@ -46,9 +46,15 @@ def forum_path(forum_id):
@bp.route("/<int:forum_id>")
def view_forum(forum_id):
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))
forum = db.execute("SELECT * FROM forums WHERE id = ?",(forum_id,)).fetchone()
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,
@@ -59,7 +65,7 @@ def view_forum(forum_id):
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};
""",(forum_id,)).fetchall()
thread_tags = {}
thread_polls = {}
diff --git a/apioforum/static/style.css b/apioforum/static/style.css
index 1f089a0..ea8cabb 100644
--- a/apioforum/static/style.css
+++ b/apioforum/static/style.css
@@ -220,4 +220,5 @@ blockquote {
content: "/\00a0";
padding: 8px;
}
-
+
+
diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html
index 475fdc2..978f1a2 100644
--- a/apioforum/templates/view_forum.html
+++ b/apioforum/templates/view_forum.html
@@ -49,6 +49,16 @@
{% else %}
please log in to create a new thread
{% endif %}
+<form class="inline-form small-form" method="get">
+ <label for="sortby">sort threads by</label>
+ <select name="sortby" name="sortby">
+ <option selected value="ad">last activity (newest first)</option>
+ <option value="aa">last activity (oldest first)</option>
+ <option value="cd">creation time (newest first)</option>
+ <option value="ca">creation time (oldest first)</option>
+ </select>
+ <input type="submit" value="go">
+</form>
</p>
<div class="thread-list">
{%for thread in threads%}