s/subforum/forum

This commit is contained in:
David Hoppenbrouwers
2022-10-07 23:36:21 +02:00
parent 1eb77bc340
commit 2dcf9c5cf7
6 changed files with 17 additions and 16 deletions

View File

@@ -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)
)

View File

@@ -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/<int:forum_id>/')
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,

View File

@@ -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,

View File

@@ -6,10 +6,10 @@
<th>Forum</th>
<th>Last update</th>
</tr>
{% for id, name, description, t_id, t_title, t_mtime in subforums %}
{% for id, name, description, t_id, t_title, t_mtime in forums %}
<tr>
<td>
<p><a href="{{ url_for('subforum', forum_id = id) }}"><b>{{ name }}</b></a></p>
<p><a href="{{ url_for('forum', forum_id = id) }}"><b>{{ name }}</b></a></p>
<p>{{ description }}</p>
</td>
{% if t_id %}

View File

@@ -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)