Make server-side slug generation respect WAGTAIL_ALLOW_UNICODE_SLUGS (#5808)

This commit is contained in:
Arkadiusz Ryś 2020-02-05 13:18:17 +01:00 committed by Matt Westcott
parent afd707f6b4
commit 47f677577e
5 changed files with 18 additions and 2 deletions

View file

@ -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)

View file

@ -430,6 +430,7 @@ Contributors
* Eric Sherman
* Martin Coote
* Simon Evans
* Arkadiusz Michał Ryś
Translators
===========

View file

@ -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

View file

@ -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:

View file

@ -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())