diff --git a/app/models.py b/app/models.py index 2c9d267..1983a43 100644 --- a/app/models.py +++ b/app/models.py @@ -172,7 +172,7 @@ class Topics(Model): name = name.strip() description = description.strip() now = int(time.time()) - slug = f'{slugify(name)}-{now}' + slug = slugify(name, max_length=50) topic_count = Topics.count() return Topics.create({ @@ -287,7 +287,7 @@ class Threads(Model): def new(cls, user_id: int, topic_id: int, title: str, content: str, language: str = 'babycode') -> Threads: from slugify import slugify now = int(time.time()) - slug = f'{slugify(title)}-{now}' + slug = slugify(title, max_length=50) thread = Threads.create({ 'topic_id': topic_id, 'user_id': user_id, diff --git a/app/routes/mod.py b/app/routes/mod.py index 91cf217..ca2983e 100644 --- a/app/routes/mod.py +++ b/app/routes/mod.py @@ -106,7 +106,7 @@ def edit_topic_post(topic_id): topic.update({ 'name': target_name, 'description': request.form.get('description').strip(), - 'slug': slugify(target_name[:50]), + 'slug': slugify(target_name, max_length=50), }) return redirect(url_for('topics.topic_by_id', topic_id=topic.id)) diff --git a/app/routes/threads.py b/app/routes/threads.py index 24165c6..c50dced 100644 --- a/app/routes/threads.py +++ b/app/routes/threads.py @@ -33,7 +33,7 @@ def thread(thread_id, slug): if not thread: abort(404) if thread.slug != slug: - return redirect(url_for('.thread', thread_id=thread_id, slug=thread.slug, **request.kwargs)) + return redirect(url_for('.thread', thread_id=thread_id, slug=thread.slug, **request.args)) topic = Topics.find({'id': thread.topic_id}) started_by = Users.find({'id': thread.user_id}) @@ -115,7 +115,8 @@ def edit_post(thread_id): abort(400) if new_title != thread.title: - thread.update({'title': new_title}) + from slugify import slugify + thread.update({'title': new_title, 'slug': slugify(new_title, max_length=50)}) return redirect(url_for('.thread_by_id', thread_id=thread_id))