slugify to a max of 50 and remove date
This commit is contained in:
@@ -172,7 +172,7 @@ class Topics(Model):
|
|||||||
name = name.strip()
|
name = name.strip()
|
||||||
description = description.strip()
|
description = description.strip()
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
slug = f'{slugify(name)}-{now}'
|
slug = slugify(name, max_length=50)
|
||||||
|
|
||||||
topic_count = Topics.count()
|
topic_count = Topics.count()
|
||||||
return Topics.create({
|
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:
|
def new(cls, user_id: int, topic_id: int, title: str, content: str, language: str = 'babycode') -> Threads:
|
||||||
from slugify import slugify
|
from slugify import slugify
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
slug = f'{slugify(title)}-{now}'
|
slug = slugify(title, max_length=50)
|
||||||
thread = Threads.create({
|
thread = Threads.create({
|
||||||
'topic_id': topic_id,
|
'topic_id': topic_id,
|
||||||
'user_id': user_id,
|
'user_id': user_id,
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ def edit_topic_post(topic_id):
|
|||||||
topic.update({
|
topic.update({
|
||||||
'name': target_name,
|
'name': target_name,
|
||||||
'description': request.form.get('description').strip(),
|
'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))
|
return redirect(url_for('topics.topic_by_id', topic_id=topic.id))
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ def thread(thread_id, slug):
|
|||||||
if not thread:
|
if not thread:
|
||||||
abort(404)
|
abort(404)
|
||||||
if thread.slug != slug:
|
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})
|
topic = Topics.find({'id': thread.topic_id})
|
||||||
started_by = Users.find({'id': thread.user_id})
|
started_by = Users.find({'id': thread.user_id})
|
||||||
@@ -115,7 +115,8 @@ def edit_post(thread_id):
|
|||||||
abort(400)
|
abort(400)
|
||||||
|
|
||||||
if new_title != thread.title:
|
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))
|
return redirect(url_for('.thread_by_id', thread_id=thread_id))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user