remove dependency on unicode-slugify, use Django builtin function

This commit is contained in:
Petr Dlouhý 2024-04-18 13:09:58 +02:00
parent 2497ce11ea
commit c7e14fe60b
5 changed files with 35 additions and 3 deletions

View file

@ -12,10 +12,10 @@ from django.utils.translation import gettext_lazy as _
from mptt.fields import TreeForeignKey from mptt.fields import TreeForeignKey
from mptt.managers import TreeManager from mptt.managers import TreeManager
from mptt.models import MPTTModel from mptt.models import MPTTModel
from slugify import slugify
from .editor.tree_editor import TreeEditor from .editor.tree_editor import TreeEditor
from .settings import ALLOW_SLUG_CHANGE, SLUG_TRANSLITERATOR from .settings import ALLOW_SLUG_CHANGE, SLUG_TRANSLITERATOR
from .utils import slugify
class CategoryManager(models.Manager): class CategoryManager(models.Manager):

View file

@ -2,11 +2,12 @@
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.db import transaction from django.db import transaction
from slugify import slugify
from categories.models import Category from categories.models import Category
from categories.settings import SLUG_TRANSLITERATOR from categories.settings import SLUG_TRANSLITERATOR
from ...utils import slugify
class Command(BaseCommand): class Command(BaseCommand):
"""Import category trees from a file.""" """Import category trees from a file."""

View file

@ -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",
"user@domain.com": "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
categories/utils.py Normal file
View file

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

View file

@ -1,2 +1 @@
django-mptt django-mptt
unicode-slugify