aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--apioforum/forum.py23
-rw-r--r--apioforum/templates/view_forum.html3
2 files changed, 15 insertions, 11 deletions
diff --git a/apioforum/forum.py b/apioforum/forum.py
index 9284671..7d6f0f0 100644
--- a/apioforum/forum.py
+++ b/apioforum/forum.py
@@ -20,14 +20,15 @@ def not_actual_index():
def forum_path(forum_id):
db = get_db()
- i = forum_id
- path = []
- while i != None:
- forum = db.execute("SELECT * FROM forums WHERE id = ?",(i,)).fetchone()
- path.append(forum)
- i = forum['parent']
- path.reverse()
- return path
+ ancestors = db.execute("""
+ WITH RECURSIVE fs AS
+ (SELECT * FROM forums WHERE id = ?
+ UNION ALL
+ SELECT forums.* FROM forums, fs WHERE fs.parent=forums.id)
+ SELECT * FROM fs;
+ """,(forum_id,)).fetchall()
+ ancestors.reverse()
+ return ancestors
@bp.route("/<int:forum_id>")
def view_forum(forum_id):
@@ -59,7 +60,7 @@ def view_forum(forum_id):
subforums_rows = db.execute("""
SELECT max(threads.updated) as updated, forums.* FROM forums
- JOIN threads ON threads.forum=forums.id
+ LEFT OUTER JOIN threads ON threads.forum=forums.id
WHERE parent = ?
GROUP BY forums.id
ORDER BY name ASC
@@ -68,8 +69,10 @@ def view_forum(forum_id):
for s in subforums_rows:
a={}
a.update(s)
- a['updated'] = datetime.datetime.fromisoformat(a['updated'])
+ if a['updated'] is not None:
+ a['updated'] = datetime.datetime.fromisoformat(a['updated'])
subforums.append(a)
+
return render_template("view_forum.html",
forum=forum,
diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html
index 9dc4227..3529caa 100644
--- a/apioforum/templates/view_forum.html
+++ b/apioforum/templates/view_forum.html
@@ -9,8 +9,9 @@
{%block nmcontent%}
<main class="widemain">
+{% if forum.description %}
{{forum.description|md|safe}}
-
+{% endif %}
{% if subforums %}
<h2>subforae</h2>