add most mod routes

This commit is contained in:
2026-04-16 23:11:19 +03:00
parent d6b44da6c2
commit 9c4f271259
14 changed files with 216 additions and 34 deletions

View File

@@ -123,6 +123,22 @@ class Topics(Model):
GROUP BY topics.id ORDER BY topics.sort_order ASC"""
return db.query(q)
@classmethod
def new(_cls, name: str, description: str) -> Topics:
from slugify import slugify
name = name.strip()
description = description.strip()
now = int(time.time())
slug = f'{slugify(name)}-{now}'
topic_count = Topics.count()
return Topics.create({
'name': name,
'description': description,
'slug': slug,
'sort_order': topic_count + 1,
})
def get_threads(self, per_page, page, sort_by = 'activity'):
order_clause = ''
if sort_by == 'thread':
@@ -198,10 +214,13 @@ class Topics(Model):
users u ON u.id = posts.user_id
WHERE
threads.topic_id = ?
ORDER BY threads.created_at DESC"""
ORDER BY threads.created_at DESC"""
return db.query(q, self.id)
def locked(self):
return bool(self.is_locked)
class Threads(Model):
table = 'threads'