slugify to a max of 50 and remove date

This commit is contained in:
2026-05-30 09:18:42 +03:00
parent d87d9c2977
commit ae9d33473c
3 changed files with 6 additions and 5 deletions

View File

@@ -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,

View File

@@ -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))

View File

@@ -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))