From 06d03e2fd1145271271b6d971fe6657da5bcf400 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Wed, 23 Jun 2021 18:14:12 +0000 Subject: subforums work properly again now, i think --- apioforum/forum.py | 23 +++++++++++++---------- apioforum/templates/view_forum.html | 3 ++- 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("/") 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%}
+{% if forum.description %} {{forum.description|md|safe}} - +{% endif %} {% if subforums %}

subforae

-- cgit v1.2.3