Skip to content

Commit

Permalink
Add new setting: disable unicode in slugs. (#727)
Browse files Browse the repository at this point in the history
Default is still allow_unicode=True, add "BLOG_UNICODE_SLUGS" setting.

Fix #707.

Co-authored-by: Corentin Bettiol <cb@kapt.mobi>
  • Loading branch information
yakky and corentinbettiol authored Apr 20, 2023
1 parent ad80132 commit c6f85df
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions changes/707.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add optional BLOG_UNICODE_SLUGS setting that disable unicode in blog posts slugs.
4 changes: 3 additions & 1 deletion djangocms_blog/fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django.utils.text import slugify as django_slugify

from .settings import get_setting

__all__ = ["slugify"]


def slugify(base):
return django_slugify(base, allow_unicode=True)
return django_slugify(base, allow_unicode=get_setting("UNICODE_SLUGS"))
4 changes: 3 additions & 1 deletion djangocms_blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ class Post(KnockerModel, BlogMetaMixin, TranslatableModel):

translations = TranslatedFields(
title=models.CharField(_("title"), max_length=752),
slug=models.SlugField(_("slug"), max_length=752, blank=True, db_index=True, allow_unicode=True),
slug=models.SlugField(
_("slug"), max_length=752, blank=True, db_index=True, allow_unicode=get_setting("UNICODE_SLUGS")
),
subtitle=models.CharField(verbose_name=_("subtitle"), max_length=767, blank=True, default=""),
abstract=HTMLField(_("abstract"), blank=True, default="", configuration="BLOG_ABSTRACT_CKEDITOR"),
meta_description=models.TextField(verbose_name=_("post meta description"), blank=True, default=""),
Expand Down
8 changes: 8 additions & 0 deletions djangocms_blog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
Permalinks styles.
"""

BLOG_UNICODE_SLUGS = True
"""
.. _UNICODE_SLUGS:
Allow unicode chars in auto-generated slugs.
"""


PERMALINKS_URLS = { # noqa
PERMALINK_TYPE_FULL_DATE: "<int:year>/<int:month>/<int:day>/<str:slug>/",
PERMALINK_TYPE_SHORT_DATE: "<int:year>/<int:month>/<str:slug>/",
Expand Down

0 comments on commit c6f85df

Please sign in to comment.