rewrite threads routes to include id
This commit is contained in:
@@ -5,11 +5,21 @@ import math
|
||||
|
||||
bp = Blueprint('threads', __name__, url_prefix='/threads/')
|
||||
|
||||
@bp.get('/<slug>/')
|
||||
def thread(slug):
|
||||
thread = Threads.find({'slug': slug})
|
||||
@bp.get('/<int:thread_id>/')
|
||||
def thread_by_id(thread_id):
|
||||
thread = Threads.find({'id': thread_id})
|
||||
if not thread:
|
||||
abort(404)
|
||||
return redirect(url_for('.thread', thread_id=thread_id, slug=thread.slug, **request.args))
|
||||
|
||||
@bp.get('/<int:thread_id>/<slug>/')
|
||||
def thread(thread_id, slug):
|
||||
thread = Threads.find({'id': thread_id})
|
||||
if not thread:
|
||||
abort(404)
|
||||
if thread.slug != slug:
|
||||
return redirect(url_for('.thread', thread_id=thread_id, slug=thread.slug, **request.kwargs))
|
||||
|
||||
topic = Topics.find({'id': thread.topic_id})
|
||||
started_by = Users.find({'id': thread.user_id})
|
||||
PER_PAGE = 10
|
||||
@@ -34,21 +44,21 @@ def thread(slug):
|
||||
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/')
|
||||
@bp.post('/<int:thread_id>/reply/')
|
||||
@login_required
|
||||
def reply(slug):
|
||||
def reply(thread_id):
|
||||
user = get_active_user()
|
||||
thread = Threads.find({'slug': slug})
|
||||
thread = Threads.find({'id': thread_id})
|
||||
if not thread:
|
||||
abort(404)
|
||||
if thread.locked() and not user.is_mod():
|
||||
# TODO: flash
|
||||
return redirect(url_for('.thread', slug=slug))
|
||||
return redirect(url_for('.thread_by_id', thread_id=thread_id))
|
||||
post = Posts.new(user.id, thread.id, request.form.get('babycode_content'))
|
||||
return redirect(url_for('.thread', slug=slug, after=post.id, _anchor=f'post-{post.id}'))
|
||||
return redirect(url_for('.thread_by_id', thread_id=thread_id, after=post.id, _anchor=f'post-{post.id}'))
|
||||
|
||||
@bp.get('/<slug>/feed.atom/')
|
||||
def feed(slug):
|
||||
@bp.get('/<int:thread_id>/feed.atom/')
|
||||
def feed(thread_id):
|
||||
return 'stub'
|
||||
|
||||
@bp.get('/new/')
|
||||
|
||||
Reference in New Issue
Block a user