File tree 5 files changed +35
-3
lines changed
5 files changed +35
-3
lines changed Original file line number Diff line number Diff line change 12
12
from mptt .fields import TreeForeignKey
13
13
from mptt .managers import TreeManager
14
14
from mptt .models import MPTTModel
15
- from slugify import slugify
16
15
17
16
from .editor .tree_editor import TreeEditor
18
17
from .settings import ALLOW_SLUG_CHANGE , SLUG_TRANSLITERATOR
18
+ from .utils import slugify
19
19
20
20
21
21
class CategoryManager (models .Manager ):
Original file line number Diff line number Diff line change 2
2
3
3
from django .core .management .base import BaseCommand , CommandError
4
4
from django .db import transaction
5
- from slugify import slugify
6
5
7
6
from categories .models import Category
8
7
from categories .settings import SLUG_TRANSLITERATOR
9
8
9
+ from ...utils import slugify
10
+
10
11
11
12
class Command (BaseCommand ):
12
13
"""Import category trees from a file."""
Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change 1
1
django-mptt
2
- unicode-slugify
You can’t perform that action at this time.
0 commit comments