add infobox support

This commit is contained in:
2026-04-25 16:15:37 +03:00
parent 3d7188eb71
commit 29f2318cba
7 changed files with 59 additions and 6 deletions

View File

@@ -1,6 +1,8 @@
from flask import Blueprint, abort, redirect, url_for, request, render_template
from flask import Blueprint, abort, redirect, url_for, request, render_template, flash
from ..constants import InfoboxKind
from ..auth import is_logged_in, get_active_user, csrf_verified
from ..models import Topics, Threads
from slugify import slugify
bp = Blueprint('mod', __name__, url_prefix='/mod/')
@bp.before_request
@@ -39,9 +41,21 @@ def edit_topic_post(topic_id):
topic = Topics.find({'id': topic_id})
if not topic:
abort(404)
target_name = request.form.get('name').strip()
name_exists = Topics.count([
('lower(name)', '=', target_name.lower()),
('id', '!=', topic.id)
]) > 0
if name_exists:
flash(f'A topic named "{target_name}" already exists.', InfoboxKind.ERROR)
return redirect(url_for('.edit_topic', topic_id=topic_id))
topic.update({
'name': request.form.get('name').strip(),
'name': target_name,
'description': request.form.get('description').strip(),
'slug': slugify(target_name[:50]),
})
return redirect(url_for('topics.topic_by_id', topic_id=topic.id))