From 47f677577e1df485c57cd6155b9e5fa68afbd69d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20Ry=C5=9B?= Date: Wed, 5 Feb 2020 13:18:17 +0100 Subject: [PATCH] Make server-side slug generation respect WAGTAIL_ALLOW_UNICODE_SLUGS (#5808) --- CHANGELOG.txt | 3 ++- CONTRIBUTORS.rst | 1 + docs/releases/2.9.rst | 1 + wagtail/core/models.py | 3 ++- wagtail/core/tests/test_page_model.py | 12 ++++++++++++ 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 4b46f9ef0..860c83d6e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -5,12 +5,13 @@ Changelog ~~~~~~~~~~~~~~~~ * Reduced contrast of rich text toolbar (Jack Paine) + * Support the rel attribute on custom ModelAdmin buttons (Andy Chosak) + * Server-side page slug generation now respects `WAGTAIL_ALLOW_UNICODE_SLUGS` (Arkadiusz Michał Ryś) * Fix: Added ARIA alert role to live search forms in the admin (Casper Timmers) * Fix: Reorder login form elements to match expected tab order (Kjartan Sverrisson) * Fix: Re-add 'Close Explorer' button on mobile viewports (Sævar Öfjörð Magnússon) * Fix: Add a more descriptive label to Password reset link for screen reader users (Casper Timmers, Martin Coote) * Fix: Improve Wagtail logo contrast by adding a background (Brian Edelman, Simon Evans, Ben Enright) - * Support the rel attribute on custom ModelAdmin buttons (Andy Chosak) 2.8 (03.02.2020) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index abe14e8d6..aac09fc0b 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -430,6 +430,7 @@ Contributors * Eric Sherman * Martin Coote * Simon Evans +* Arkadiusz Michał Ryś Translators =========== diff --git a/docs/releases/2.9.rst b/docs/releases/2.9.rst index 1fa1607df..3d9a1928d 100644 --- a/docs/releases/2.9.rst +++ b/docs/releases/2.9.rst @@ -16,6 +16,7 @@ Other features * Reduced contrast of rich text toolbar (Jack Paine) * Support the rel attribute on custom ModelAdmin buttons (Andy Chosak) + * Server-side page slug generation now respects ``WAGTAIL_ALLOW_UNICODE_SLUGS`` (Arkadiusz Michał Ryś) Bug fixes diff --git a/wagtail/core/models.py b/wagtail/core/models.py index be8cbf443..cb4799d21 100644 --- a/wagtail/core/models.py +++ b/wagtail/core/models.py @@ -431,7 +431,8 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase): if not self.slug: # Try to auto-populate slug from title - base_slug = slugify(self.title, allow_unicode=True) + allow_unicode = getattr(settings, 'WAGTAIL_ALLOW_UNICODE_SLUGS', True) + base_slug = slugify(self.title, allow_unicode=allow_unicode) # only proceed if we get a non-empty base slug back from slugify if base_slug: diff --git a/wagtail/core/tests/test_page_model.py b/wagtail/core/tests/test_page_model.py index 539130d27..18e5fd725 100644 --- a/wagtail/core/tests/test_page_model.py +++ b/wagtail/core/tests/test_page_model.py @@ -84,6 +84,18 @@ class TestValidation(TestCase): homepage.add_child(instance=christmas_page) self.assertTrue(Page.objects.filter(id=christmas_page.id).exists()) + @override_settings(WAGTAIL_ALLOW_UNICODE_SLUGS=True) + def test_slug_generation_respects_unicode_setting_true(self): + page = Page(title="A mööse bit me önce") + Page.get_first_root_node().add_child(instance=page) + self.assertEqual(page.slug, 'a-mööse-bit-me-önce') + + @override_settings(WAGTAIL_ALLOW_UNICODE_SLUGS=False) + def test_slug_generation_respects_unicode_setting_false(self): + page = Page(title="A mööse bit me önce") + Page.get_first_root_node().add_child(instance=page) + self.assertEqual(page.slug, 'a-moose-bit-me-once') + def test_get_admin_display_title(self): homepage = Page.objects.get(url_path='/home/') self.assertEqual(homepage.draft_title, homepage.get_admin_display_title())