From 2dcf9c5cf7ef8bd9f2846fc5958c505d0d58533b Mon Sep 17 00:00:00 2001 From: David Hoppenbrouwers Date: Fri, 7 Oct 2022 23:36:21 +0200 Subject: [PATCH] s/subforum/forum --- db/sqlite.py | 17 +++++++++-------- main.py | 8 ++++---- schema.txt | 2 +- templates/{subforum.html => forum.html} | 0 templates/index.html | 4 ++-- test/init_db.txt | 2 +- 6 files changed, 17 insertions(+), 16 deletions(-) rename templates/{subforum.html => forum.html} (100%) diff --git a/db/sqlite.py b/db/sqlite.py index bbce05c..6957991 100644 --- a/db/sqlite.py +++ b/db/sqlite.py @@ -5,10 +5,10 @@ class DB: self.conn = conn pass - def get_subforums(self): + def get_forums(self): return self._db().execute(''' select f.forum_id, name, description, thread_id, title, update_time - from subforums f + from forums f left join threads t on t.thread_id = ( select tt.thread_id @@ -20,23 +20,23 @@ class DB: ''' ) - def get_subforum(self, subforum): + def get_forum(self, forum_id): return self._db().execute(''' select name, description - from subforums + from forums where forum_id = ? ''', - (subforum,) + (forum_id,) ).fetchone() - def get_threads(self, subforum): + def get_threads(self, forum_id): return self._db().execute(''' select t.thread_id, title, t.create_time, t.update_time, t.author_id, name, count(1) from threads t, users, comments c where forum_id = ? and user_id = t.author_id and t.thread_id = c.thread_id group by t.thread_id ''', - (subforum,) + (forum_id,) ) def get_thread(self, thread): @@ -191,10 +191,11 @@ class DB: (thread_id, author_id, text, time, time, thread_id) ) if c.rowcount > 0: + print('SHIT') c.execute(''' update threads set update_time = ? - where threads.thread_id = ? + where thread_id = ? ''', (time, thread_id) ) diff --git a/main.py b/main.py index fc2e806..798e038 100644 --- a/main.py +++ b/main.py @@ -14,14 +14,14 @@ app.config['SECRET_KEY'] = 'totally random' @app.route('/') def index(): - return render_template('index.html', title = NAME, subforums = db.get_subforums()) + return render_template('index.html', title = NAME, forums = db.get_forums()) @app.route('/forum//') -def subforum(forum_id): - title, description = db.get_subforum(forum_id) +def forum(forum_id): + title, description = db.get_forum(forum_id) threads = db.get_threads(forum_id) return render_template( - 'subforum.html', + 'forum.html', title = title, forum_id = forum_id, description = description, diff --git a/schema.txt b/schema.txt index d0a47fa..9d59e9c 100644 --- a/schema.txt +++ b/schema.txt @@ -33,7 +33,7 @@ create table comments ( dead boolean not null default false ); -create table subforums ( +create table forums ( forum_id integer unique not null primary key autoincrement, name varchar(64) not null, description text, diff --git a/templates/subforum.html b/templates/forum.html similarity index 100% rename from templates/subforum.html rename to templates/forum.html diff --git a/templates/index.html b/templates/index.html index ae9e694..6725f52 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,10 +6,10 @@ Forum Last update - {% for id, name, description, t_id, t_title, t_mtime in subforums %} + {% for id, name, description, t_id, t_title, t_mtime in forums %} -

{{ name }}

+

{{ name }}

{{ description }}

{% if t_id %} diff --git a/test/init_db.txt b/test/init_db.txt index 5a78ff8..8f9c71f 100644 --- a/test/init_db.txt +++ b/test/init_db.txt @@ -16,7 +16,7 @@ insert into users (name, password) values ( "$argon2id$v=19$m=65536,t=3,p=4$9v5fS2ktxTinNEbIGUOoFQ$LMdEuAuuTCJ7utOE88+nXn7o6R/DEKY8ZA6wV+YkVGQ" ); -insert into subforums (name, description, allowed_roles_mask) +insert into forums (name, description, allowed_roles_mask) values ("Earth", "The totality of all space and time; all that is, has been, and will be.", 1); insert into threads (author_id, forum_id, create_time, modify_time, update_time, title, text)