diff --git a/app/routes/mod.py b/app/routes/mod.py index d164c32..3e9c929 100644 --- a/app/routes/mod.py +++ b/app/routes/mod.py @@ -21,7 +21,7 @@ def new_topic(): @bp.post('/topics/new/') def new_topic_post(): 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/') def sort_topics(): @@ -43,7 +43,7 @@ def edit_topic_post(topic_id): 'name': request.form.get('name').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//lock/') def lock_topic(topic_id): @@ -51,7 +51,7 @@ def lock_topic(topic_id): if not topic: abort(404) 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//move/') def move_thread(thread_id): diff --git a/app/routes/topics.py b/app/routes/topics.py index b9207b3..b1e7ebb 100644 --- a/app/routes/topics.py +++ b/app/routes/topics.py @@ -10,11 +10,21 @@ def all_topics(): topic_list = Topics.get_list() return render_template('topics/topics.html', topics=topic_list) -@bp.get('//') -def topic(slug): - topic = Topics.find({'slug': slug}) +@bp.get('//') +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('///') +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('//feed.atom') -def feed(slug): +@bp.get('//feed.atom/') +def feed(topic_id): return 'stub' diff --git a/app/templates/threads/thread.html b/app/templates/threads/thread.html index cf5b434..76aeb8d 100644 --- a/app/templates/threads/thread.html +++ b/app/templates/threads/thread.html @@ -5,7 +5,7 @@ {%- block content -%} {%- set td -%}
    -
  • Started by {{started_by.get_readable_name()}} in topic {{topic.name}}
  • +
  • Started by {{started_by.get_readable_name()}} in topic {{topic.name}}
  • {%- if thread.locked() or thread.stickied() -%} {%- if thread.locked() -%}
  • Locked
  • diff --git a/app/templates/topics/topic.html b/app/templates/topics/topic.html index 0a31159..11e56ec 100644 --- a/app/templates/topics/topic.html +++ b/app/templates/topics/topic.html @@ -16,7 +16,7 @@ {%- if is_logged_in() and get_active_user().can_post_to_topic(topic) -%} New thread {%- endif -%} - Subscribe via RSS + Subscribe via RSS