thread page mostly finished

This commit is contained in:
2026-04-15 23:11:24 +03:00
parent 7db111d18b
commit d0daaf4494
13 changed files with 330 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
from flask import Blueprint, redirect, url_for, render_template, request, session
from flask import Blueprint, redirect, url_for, render_template, request, session, abort
from ..models import Topics, Threads
import math
@@ -12,15 +12,18 @@ def all_topics():
@bp.get('/<slug>')
def topic(slug):
t = Topics.find({'slug': slug})
if not t:
return 'stub'
topic = Topics.find({'slug': slug})
if not topic:
abort(404)
sort_by = request.args.get('sort_by', default=session.get('sort_by', default='activity'))
PER_PAGE = 10
threads_count = Threads.count({'topic_id': t.id})
threads_count = Threads.count({'topic_id': topic.id})
page_count = max(1, math.ceil(threads_count / PER_PAGE))
page = max(1, min(int(request.args.get('page', default=1)), page_count))
return render_template('topics/topic.html', topic=t, threads=t.get_threads(PER_PAGE, page, sort_by), sort_by=sort_by, page=page, page_count=page_count)
try:
page = max(1, min(int(request.args.get('page', default=1)), page_count))
except ValueError:
abort(404)
return render_template('topics/topic.html', topic=topic, threads=topic.get_threads(PER_PAGE, page, sort_by), sort_by=sort_by, page=page, page_count=page_count)
@bp.get('/<slug>/feed.atom')
def feed(slug):