mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
remove dependency on unicode-slugify, use Django builtin function
This commit is contained in:
parent
2497ce11ea
commit
c7e14fe60b
5 changed files with 35 additions and 3 deletions
|
|
@ -12,10 +12,10 @@ from django.utils.translation import gettext_lazy as _
|
|||
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):
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
24
categories/tests/test_utils.py
Normal file
24
categories/tests/test_utils.py
Normal 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
8
categories/utils.py
Normal 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)
|
||||
|
|
@ -1,2 +1 @@
|
|||
django-mptt
|
||||
unicode-slugify
|
||||
|
|
|
|||
Loading…
Reference in a new issue