rewrite topics routes to include id
This commit is contained in:
@@ -10,11 +10,21 @@ def all_topics():
|
||||
topic_list = Topics.get_list()
|
||||
return render_template('topics/topics.html', topics=topic_list)
|
||||
|
||||
@bp.get('/<slug>/')
|
||||
def topic(slug):
|
||||
topic = Topics.find({'slug': slug})
|
||||
@bp.get('/<int:topic_id>/')
|
||||
def topic_by_id(topic_id):
|
||||
topic = Topics.find({'id': topic_id})
|
||||
if not topic:
|
||||
abort(404)
|
||||
return redirect(url_for('.topic', topic_id=topic_id, slug=topic.slug, **request.args))
|
||||
|
||||
@bp.get('/<int:topic_id>/<slug>/')
|
||||
def topic(topic_id, slug):
|
||||
topic = Topics.find({'id': topic_id})
|
||||
if not topic:
|
||||
abort(404)
|
||||
if topic.slug != slug:
|
||||
return redirect(url_for('.topic', topic_id=topic_id, slug=topic.slug, **request.args))
|
||||
|
||||
sort_by = request.args.get('sort_by', default=session.get('sort_by', default='activity'))
|
||||
PER_PAGE = 10
|
||||
threads_count = Threads.count({'topic_id': topic.id})
|
||||
@@ -25,6 +35,6 @@ def topic(slug):
|
||||
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):
|
||||
@bp.get('/<int:topic_id>/feed.atom/')
|
||||
def feed(topic_id):
|
||||
return 'stub'
|
||||
|
||||
Reference in New Issue
Block a user