Skip to content

Commit 347b842

Browse files
committed
remove dependency on unicode-slugify, use Django builtin function
1 parent 2497ce1 commit 347b842

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

categories/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
from mptt.fields import TreeForeignKey
1313
from mptt.managers import TreeManager
1414
from mptt.models import MPTTModel
15-
from slugify import slugify
1615

1716
from .editor.tree_editor import TreeEditor
1817
from .settings import ALLOW_SLUG_CHANGE, SLUG_TRANSLITERATOR
18+
from .utils import slugify
1919

2020

2121
class CategoryManager(models.Manager):

categories/management/commands/import_categories.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
from django.core.management.base import BaseCommand, CommandError
44
from django.db import transaction
5-
from slugify import slugify
65

76
from categories.models import Category
87
from categories.settings import SLUG_TRANSLITERATOR
98

9+
from ...utils import slugify
10+
1011

1112
class Command(BaseCommand):
1213
"""Import category trees from a file."""

categories/tests/test_utils.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from django.test import TestCase
2+
3+
from ..utils import slugify
4+
5+
6+
class TestSlugify(TestCase):
7+
def test_slugify(self):
8+
string_dict = {
9+
"naïve café": "naïve-café",
10+
"spaced out": "spaced-out",
11+
"[email protected]": "userdomaincom",
12+
"100% natural": "100-natural",
13+
"über-cool": "über-cool",
14+
"façade élégant": "façade-élégant",
15+
"北京大学": "北京大学",
16+
"Толстой": "толстой",
17+
"ñoño": "ñoño",
18+
"سلام": "سلام",
19+
"Αθήνα": "Αθήνα",
20+
"こんにちは": "こんにちは",
21+
"˚č$'\\*>%ˇ'!/": "čˇ",
22+
}
23+
for key, value in string_dict.items():
24+
self.assertEqual(slugify(key), value)

categories/utils.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""This module contains utility functions that are used across the project."""
2+
3+
from django.utils.text import slugify as django_slugify
4+
5+
6+
def slugify(text):
7+
"""Slugify a string. This function is a wrapper to unify the slugify function across the project."""
8+
return django_slugify(text, allow_unicode=True)

requirements/prod.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
django-mptt
2-
unicode-slugify

0 commit comments

Comments
 (0)