Fixed slugs not being generated for unicode texts

This commit is contained in:
Swen Kooij 2017-01-26 01:18:46 +02:00
parent c01edc80f0
commit fc31e1e5f1
2 changed files with 17 additions and 1 deletions

View File

@ -83,7 +83,12 @@ class LocalizedAutoSlugField(LocalizedField):
return not type(instance).objects.filter(**unique_filter).exists() return not type(instance).objects.filter(**unique_filter).exists()
slug = self._make_unique_slug(slugify(value), lang_code, is_unique) slug = self._make_unique_slug(
slugify(value, allow_unicode=True),
lang_code,
is_unique
)
slugs.set(lang_code, slug) slugs.set(lang_code, slug)
setattr(instance, self.name, slugs) setattr(instance, self.name, slugs)

View File

@ -59,6 +59,17 @@ class LocalizedAutoSlugFieldTestCase(TestCase):
assert another_obj.slug.en == 'title-1' assert another_obj.slug.en == 'title-1'
def test_unique_slug_utf(self):
"""Tests whether generating a slug works
when the value consists completely out
of non-ASCII characters."""
obj = self.TestModel()
obj.title.en = 'مكاتب للايجار بشارع بورسعيد'
obj.save()
assert obj.slug.en == 'مكاتب-للايجار-بشارع-بورسعيد'
@staticmethod @staticmethod
def test_deconstruct(): def test_deconstruct():
"""Tests whether the :see:deconstruct """Tests whether the :see:deconstruct