thread page mostly finished
This commit is contained in:
@@ -13,3 +13,15 @@ def new_topic():
|
||||
@bp.get('/topics/sort')
|
||||
def sort_topics():
|
||||
return 'stub'
|
||||
|
||||
@bp.post('/threads/<int:thread_id>/move')
|
||||
def move_thread(thread_id):
|
||||
return 'stub'
|
||||
|
||||
@bp.post('/threads/<int:thread_id>/lock')
|
||||
def lock_thread(thread_id):
|
||||
return 'stub'
|
||||
|
||||
@bp.post('/threads/<int:thread_id>/sticky')
|
||||
def sticky_thread(thread_id):
|
||||
return 'stub'
|
||||
|
||||
7
app/routes/posts.py
Normal file
7
app/routes/posts.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from flask import Blueprint
|
||||
|
||||
bp = Blueprint('posts', __name__, url_prefix='/posts/')
|
||||
|
||||
@bp.get('/<int:post_id>/edit')
|
||||
def edit(post_id):
|
||||
return 'stub'
|
||||
@@ -1,9 +1,45 @@
|
||||
from flask import Blueprint
|
||||
from flask import Blueprint, redirect, url_for, render_template, request, abort
|
||||
|
||||
from ..models import Threads, Posts, Topics, Users, Reactions
|
||||
import math
|
||||
|
||||
bp = Blueprint('threads', __name__, url_prefix='/threads/')
|
||||
|
||||
@bp.get('/<slug>')
|
||||
def thread(slug):
|
||||
thread = Threads.find({'slug': slug})
|
||||
if not thread:
|
||||
abort(404)
|
||||
topic = Topics.find({'id': thread.topic_id})
|
||||
started_by = Users.find({'id': thread.user_id})
|
||||
PER_PAGE = 10
|
||||
posts_count = Posts.count({'thread_id': thread.id})
|
||||
page_count = max(1, math.ceil(posts_count / PER_PAGE))
|
||||
page = 1
|
||||
after = request.args.get('after', default=None)
|
||||
if after is not None:
|
||||
try:
|
||||
after_id = int(after)
|
||||
post_position = Posts.count([
|
||||
('thread_id', '=', thread.id),
|
||||
('id', '<=', after_id),
|
||||
])
|
||||
page = math.ceil((post_position) / PER_PAGE)
|
||||
except ValueError:
|
||||
abort(404)
|
||||
else:
|
||||
try:
|
||||
page = max(1, min(int(request.args.get('page', default=1)), page_count))
|
||||
except ValueError:
|
||||
abort(404)
|
||||
return render_template('threads/thread.html', thread=thread, posts=thread.get_posts(PER_PAGE, page), page=page, page_count=page_count, topic=topic, started_by=started_by, topics=Topics.get_list(), Reactions=Reactions)
|
||||
|
||||
@bp.post('/<slug>/reply')
|
||||
def reply(slug):
|
||||
return 'stub'
|
||||
|
||||
@bp.get('/<slug>/feed.atom')
|
||||
def feed(slug):
|
||||
return 'stub'
|
||||
|
||||
@bp.get('/new')
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user