ensure trailing slashes in all routes

This commit is contained in:
2026-04-17 10:45:54 +03:00
parent 9d8404b774
commit d2cdeaed1d
5 changed files with 19 additions and 19 deletions

View File

@@ -14,27 +14,27 @@ def mod_only():
def index(): def index():
return 'stub' return 'stub'
@bp.get('/topics/new') @bp.get('/topics/new/')
def new_topic(): def new_topic():
return render_template('mod/new_topic.html') return render_template('mod/new_topic.html')
@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', slug=topic.slug))
@bp.get('/topics/sort') @bp.get('/topics/sort/')
def sort_topics(): def sort_topics():
return 'stub' return 'stub'
@bp.get('/topics/<int:topic_id>/edit') @bp.get('/topics/<int:topic_id>/edit/')
def edit_topic(topic_id): def edit_topic(topic_id):
topic = Topics.find({'id': topic_id}) topic = Topics.find({'id': topic_id})
if not topic: if not topic:
abort(404) abort(404)
return render_template('mod/edit_topic.html', topic=topic) return render_template('mod/edit_topic.html', topic=topic)
@bp.post('/topics/<int:topic_id>/edit') @bp.post('/topics/<int:topic_id>/edit/')
def edit_topic_post(topic_id): def edit_topic_post(topic_id):
topic = Topics.find({'id': topic_id}) topic = Topics.find({'id': topic_id})
if not topic: if not topic:
@@ -45,7 +45,7 @@ def edit_topic_post(topic_id):
}) })
return redirect(url_for('topics.topic', slug=topic.slug)) return redirect(url_for('topics.topic', slug=topic.slug))
@bp.post('/topics/<int:topic_id>/lock') @bp.post('/topics/<int:topic_id>/lock/')
def lock_topic(topic_id): def lock_topic(topic_id):
topic = Topics.find({'id': topic_id}) topic = Topics.find({'id': topic_id})
if not topic: if not topic:
@@ -53,7 +53,7 @@ def lock_topic(topic_id):
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', slug=topic.slug))
@bp.post('/threads/<int:thread_id>/move') @bp.post('/threads/<int:thread_id>/move/')
def move_thread(thread_id): def move_thread(thread_id):
thread = Threads.find({'id': thread_id}) thread = Threads.find({'id': thread_id})
if not thread: if not thread:
@@ -64,7 +64,7 @@ def move_thread(thread_id):
thread.update({'topic_id': target_topic.id}) thread.update({'topic_id': target_topic.id})
return redirect(url_for('threads.thread', slug=thread.slug)) return redirect(url_for('threads.thread', slug=thread.slug))
@bp.post('/threads/<int:thread_id>/lock') @bp.post('/threads/<int:thread_id>/lock/')
def lock_thread(thread_id): def lock_thread(thread_id):
thread = Threads.find({'id': thread_id}) thread = Threads.find({'id': thread_id})
if not thread: if not thread:
@@ -72,7 +72,7 @@ def lock_thread(thread_id):
thread.update({'is_locked': request.form.get('lock')}) thread.update({'is_locked': request.form.get('lock')})
return redirect(url_for('threads.thread', slug=thread.slug)) return redirect(url_for('threads.thread', slug=thread.slug))
@bp.post('/threads/<int:thread_id>/sticky') @bp.post('/threads/<int:thread_id>/sticky/')
def sticky_thread(thread_id): def sticky_thread(thread_id):
thread = Threads.find({'id': thread_id}) thread = Threads.find({'id': thread_id})
if not thread: if not thread:

View File

@@ -2,6 +2,6 @@ from flask import Blueprint
bp = Blueprint('posts', __name__, url_prefix='/posts/') bp = Blueprint('posts', __name__, url_prefix='/posts/')
@bp.get('/<int:post_id>/edit') @bp.get('/<int:post_id>/edit/')
def edit(post_id): def edit(post_id):
return 'stub' return 'stub'

View File

@@ -5,7 +5,7 @@ import math
bp = Blueprint('threads', __name__, url_prefix='/threads/') bp = Blueprint('threads', __name__, url_prefix='/threads/')
@bp.get('/<slug>') @bp.get('/<slug>/')
def thread(slug): def thread(slug):
thread = Threads.find({'slug': slug}) thread = Threads.find({'slug': slug})
if not thread: if not thread:
@@ -34,7 +34,7 @@ def thread(slug):
abort(404) 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) 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('/<slug>/reply/')
@login_required @login_required
def reply(slug): def reply(slug):
user = get_active_user() user = get_active_user()
@@ -47,7 +47,7 @@ def reply(slug):
post = Posts.new(user.id, thread.id, request.form.get('babycode_content')) 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', slug=slug, after=post.id, _anchor=f'post-{post.id}'))
@bp.get('/<slug>/feed.atom') @bp.get('/<slug>/feed.atom/')
def feed(slug): def feed(slug):
return 'stub' return 'stub'
@@ -61,7 +61,7 @@ def new():
selected_topic = None selected_topic = None
return render_template('threads/new_thread.html', topics=topics, selected_topic=selected_topic) return render_template('threads/new_thread.html', topics=topics, selected_topic=selected_topic)
@bp.post('/new') @bp.post('/new/')
@login_required @login_required
def new_post(): def new_post():
try: try:

View File

@@ -10,13 +10,13 @@ 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('/<slug>/')
def topic(slug): def topic(slug):
topic = Topics.find({'slug': slug}) topic = Topics.find({'slug': slug})
if not topic: if not topic:
abort(404) abort(404)
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 = 3
threads_count = Threads.count({'topic_id': topic.id}) threads_count = Threads.count({'topic_id': topic.id})
page_count = max(1, math.ceil(threads_count / PER_PAGE)) page_count = max(1, math.ceil(threads_count / PER_PAGE))
try: try:

View File

@@ -18,12 +18,12 @@ def redirect_if_logged_in(destination='topics.all_topics'):
return wrapper return wrapper
return decorator return decorator
@bp.get('/log-in') @bp.get('/log-in/')
@redirect_if_logged_in() @redirect_if_logged_in()
def log_in(): def log_in():
return render_template('users/log_in.html') return render_template('users/log_in.html')
@bp.post('/log-in') @bp.post('/log-in/')
@redirect_if_logged_in() @redirect_if_logged_in()
def log_in_post(): def log_in_post():
username = request.form.get('username', default='').lower() username = request.form.get('username', default='').lower()
@@ -89,7 +89,7 @@ def sign_up_post():
return redirect(url_for('topics.all_topics')) return redirect(url_for('topics.all_topics'))
@bp.get('/<username>') @bp.get('/<username>/')
def user_page(username): def user_page(username):
return 'stub' return 'stub'