rewrite topics routes to include id
This commit is contained in:
@@ -21,7 +21,7 @@ def new_topic():
|
|||||||
@bp.post('/topics/new/')
|
@bp.post('/topics/new/')
|
||||||
def new_topic_post():
|
def new_topic_post():
|
||||||
topic = Topics.new(request.form.get('name'), request.form.get('description'))
|
topic = Topics.new(request.form.get('name'), request.form.get('description'))
|
||||||
return redirect(url_for('topics.topic', slug=topic.slug))
|
return redirect(url_for('topics.topic_by_id', topic_id=topic.id))
|
||||||
|
|
||||||
@bp.get('/topics/sort/')
|
@bp.get('/topics/sort/')
|
||||||
def sort_topics():
|
def sort_topics():
|
||||||
@@ -43,7 +43,7 @@ def edit_topic_post(topic_id):
|
|||||||
'name': request.form.get('name').strip(),
|
'name': request.form.get('name').strip(),
|
||||||
'description': request.form.get('description').strip(),
|
'description': request.form.get('description').strip(),
|
||||||
})
|
})
|
||||||
return redirect(url_for('topics.topic', slug=topic.slug))
|
return redirect(url_for('topics.topic_by_id', topic_id=topic.id))
|
||||||
|
|
||||||
@bp.post('/topics/<int:topic_id>/lock/')
|
@bp.post('/topics/<int:topic_id>/lock/')
|
||||||
def lock_topic(topic_id):
|
def lock_topic(topic_id):
|
||||||
@@ -51,7 +51,7 @@ def lock_topic(topic_id):
|
|||||||
if not topic:
|
if not topic:
|
||||||
abort(404)
|
abort(404)
|
||||||
topic.update({'is_locked': request.form.get('lock', default=0)})
|
topic.update({'is_locked': request.form.get('lock', default=0)})
|
||||||
return redirect(url_for('topics.topic', slug=topic.slug))
|
return redirect(url_for('topics.topic_by_id', topic_id=topic.id))
|
||||||
|
|
||||||
@bp.post('/threads/<int:thread_id>/move/')
|
@bp.post('/threads/<int:thread_id>/move/')
|
||||||
def move_thread(thread_id):
|
def move_thread(thread_id):
|
||||||
|
|||||||
@@ -10,11 +10,21 @@ def all_topics():
|
|||||||
topic_list = Topics.get_list()
|
topic_list = Topics.get_list()
|
||||||
return render_template('topics/topics.html', topics=topic_list)
|
return render_template('topics/topics.html', topics=topic_list)
|
||||||
|
|
||||||
@bp.get('/<slug>/')
|
@bp.get('/<int:topic_id>/')
|
||||||
def topic(slug):
|
def topic_by_id(topic_id):
|
||||||
topic = Topics.find({'slug': slug})
|
topic = Topics.find({'id': topic_id})
|
||||||
if not topic:
|
if not topic:
|
||||||
abort(404)
|
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'))
|
sort_by = request.args.get('sort_by', default=session.get('sort_by', default='activity'))
|
||||||
PER_PAGE = 10
|
PER_PAGE = 10
|
||||||
threads_count = Threads.count({'topic_id': topic.id})
|
threads_count = Threads.count({'topic_id': topic.id})
|
||||||
@@ -25,6 +35,6 @@ def topic(slug):
|
|||||||
abort(404)
|
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)
|
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')
|
@bp.get('/<int:topic_id>/feed.atom/')
|
||||||
def feed(slug):
|
def feed(topic_id):
|
||||||
return 'stub'
|
return 'stub'
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
{%- block content -%}
|
{%- block content -%}
|
||||||
{%- set td -%}
|
{%- set td -%}
|
||||||
<ul class="horizontal">
|
<ul class="horizontal">
|
||||||
<li>Started by <a href="{{url_for('users.user_page', username=started_by.username)}}">{{started_by.get_readable_name()}}</a> in topic <a href="{{url_for('topics.topic', slug=topic.slug)}}">{{topic.name}}</a></li>
|
<li>Started by <a href="{{url_for('users.user_page', username=started_by.username)}}">{{started_by.get_readable_name()}}</a> in topic <a href="{{url_for('topics.topic_by_id', topic_id=topic.id)}}">{{topic.name}}</a></li>
|
||||||
{%- if thread.locked() or thread.stickied() -%}
|
{%- if thread.locked() or thread.stickied() -%}
|
||||||
{%- if thread.locked() -%}
|
{%- if thread.locked() -%}
|
||||||
<li class="visible">Locked</li>
|
<li class="visible">Locked</li>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
{%- if is_logged_in() and get_active_user().can_post_to_topic(topic) -%}
|
{%- if is_logged_in() and get_active_user().can_post_to_topic(topic) -%}
|
||||||
<a href="{{url_for('threads.new', topic_id=topic.id)}}" class="linkbutton">New thread</a>
|
<a href="{{url_for('threads.new', topic_id=topic.id)}}" class="linkbutton">New thread</a>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
<a href="{{url_for('topics.feed', slug=topic.slug)}}" class="linkbutton rss">Subscribe via RSS</a>
|
<a href="{{url_for('topics.feed', topic_id=topic.id)}}" class="linkbutton rss">Subscribe via RSS</a>
|
||||||
<form method="GET">
|
<form method="GET">
|
||||||
<select name="sort_by">
|
<select name="sort_by">
|
||||||
<option value="activity"{% if sort_by == 'activity' %}selected{% endif %}>Sorted by activity</option>
|
<option value="activity"{% if sort_by == 'activity' %}selected{% endif %}>Sorted by activity</option>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
{%- for topic in topics -%}
|
{%- for topic in topics -%}
|
||||||
<div class="topic-info plank">
|
<div class="topic-info plank">
|
||||||
<div class="title-container">
|
<div class="title-container">
|
||||||
<a class="info" href="{{url_for('topics.topic', slug=topic.slug)}}">{{topic.name}}</a>
|
<a class="info" href="{{url_for('topics.topic_by_id', topic_id=topic.id)}}">{{topic.name}}</a>
|
||||||
</div>
|
</div>
|
||||||
<div>{{topic.description}}</div>
|
<div>{{topic.description}}</div>
|
||||||
<ul class="horizontal">
|
<ul class="horizontal">
|
||||||
|
|||||||
Reference in New Issue
Block a user