-
-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve unicode when slugifying by default
This change is motivated by the many many people using non-latin languages who experience the (rather baffling) behavior of outright stripping characters when generating slugs from stuff that doesn't fit into ASCII. We went through loads of pain as a programming community to get to nicely supporting unicode everywhere, it's time to take advantage of that fact and just let people have stuff appear in their native language as much as possible.
- Loading branch information
Showing
6 changed files
with
102 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 2.2.26 on 2022-04-24 20:25 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("taggit", "0004_alter_taggeditem_content_type_alter_taggeditem_tag"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="tag", | ||
name="slug", | ||
field=models.SlugField( | ||
allow_unicode=True, max_length=100, unique=True, verbose_name="slug" | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.test import TestCase, override_settings | ||
|
||
from tests.models import TestModel | ||
|
||
|
||
class TestSlugification(TestCase): | ||
def test_unicode_slugs(self): | ||
""" | ||
Confirm the preservation of unicode in slugification by default | ||
""" | ||
sample_obj = TestModel.objects.create() | ||
# a unicode tag will be slugified for space reasons but | ||
# unicode-ness will be kept by default | ||
sample_obj.tags.add("あい うえお") | ||
self.assertEqual([tag.slug for tag in sample_obj.tags.all()], ["あい-うえお"]) | ||
|
||
def test_old_slugs(self): | ||
""" | ||
Test that the setting that gives us the old slugification behavior | ||
is in place | ||
""" | ||
with override_settings(TAGGIT_STRIP_UNICODE_WHEN_SLUGIFYING=True): | ||
sample_obj = TestModel.objects.create() | ||
# a unicode tag will be slugified for space reasons but | ||
# unicode-ness will be kept by default | ||
sample_obj.tags.add("あい うえお") | ||
self.assertEqual([tag.slug for tag in sample_obj.tags.all()], [""]) |