Skip to content

Commit

Permalink
remove dependency on unicode-slugify, use Django builtin function
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Apr 18, 2024
1 parent 2497ce1 commit 347b842
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion categories/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
from mptt.fields import TreeForeignKey
from mptt.managers import TreeManager
from mptt.models import MPTTModel
from slugify import slugify

from .editor.tree_editor import TreeEditor
from .settings import ALLOW_SLUG_CHANGE, SLUG_TRANSLITERATOR
from .utils import slugify


class CategoryManager(models.Manager):
Expand Down
3 changes: 2 additions & 1 deletion categories/management/commands/import_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

from django.core.management.base import BaseCommand, CommandError
from django.db import transaction
from slugify import slugify

from categories.models import Category
from categories.settings import SLUG_TRANSLITERATOR

from ...utils import slugify


class Command(BaseCommand):
"""Import category trees from a file."""
Expand Down
24 changes: 24 additions & 0 deletions categories/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.test import TestCase

from ..utils import slugify


class TestSlugify(TestCase):
def test_slugify(self):
string_dict = {
"naïve café": "naïve-café",
"spaced out": "spaced-out",
"[email protected]": "userdomaincom",
"100% natural": "100-natural",
"über-cool": "über-cool",
"façade élégant": "façade-élégant",
"北京大学": "北京大学",
"Толстой": "толстой",
"ñoño": "ñoño",
"سلام": "سلام",
"Αθήνα": "Αθήνα",
"こんにちは": "こんにちは",
"˚č$'\\*>%ˇ'!/": "čˇ",
}
for key, value in string_dict.items():
self.assertEqual(slugify(key), value)
8 changes: 8 additions & 0 deletions categories/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""This module contains utility functions that are used across the project."""

from django.utils.text import slugify as django_slugify


def slugify(text):
"""Slugify a string. This function is a wrapper to unify the slugify function across the project."""
return django_slugify(text, allow_unicode=True)
1 change: 0 additions & 1 deletion requirements/prod.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
django-mptt
unicode-slugify

0 comments on commit 347b842

Please sign in to comment.