Skip to content

remove dependency on unicode-slugify, use Django builtin function #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading