From 52b01cda67435b9214be6d47555d7bb436dc3472 Mon Sep 17 00:00:00 2001 From: Andy Chosak Date: Wed, 7 Aug 2019 17:00:02 -0400 Subject: [PATCH] Don't use page admin title when editing rich text (#5491) When editing a rich text field and entering a link to a page whose Page type overrides get_admin_display_title, the custom admin display title is used both when browsing to select the page to link to and also when viewing the rich text editor. The first behavior is consistent with how custom admin display titles are used throughout the admin, but the second behavior is not. The Wagtail user should be able to use the rich text field as a reasonable preview of what the rendered content will look like for the end user. To do this, the "real" page title should be used, not the admin one. This commit alters the data that gets passed to the rich text editor so that its title is the real page title and not the admin one. Fixes issue 5131. --- CHANGELOG.txt | 1 + docs/releases/2.7.rst | 1 + .../wagtailadmin/pages/listing/_page_title_choose.html | 2 +- wagtail/admin/tests/test_page_chooser.py | 8 +++++++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 026c1f7e54..c3cd3f074a 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -14,6 +14,7 @@ Changelog * Fix: Prevent exception when deleting a model with a protected One-to-one relationship (Neal Todd) * Fix: Added labels to snippet bulk edit checkboxes for screen reader users (Martey Dodoo) * Fix: Middleware responses during page preview are now properly returned to the user (Matt Westcott) + * Fix: Default text of page links in rich text uses the public page title rather than the admin display title (Andy Chosak) 2.6.1 (05.08.2019) diff --git a/docs/releases/2.7.rst b/docs/releases/2.7.rst index dae9e5e447..126ca5fb90 100644 --- a/docs/releases/2.7.rst +++ b/docs/releases/2.7.rst @@ -32,6 +32,7 @@ Bug fixes * Prevent exception when deleting a model with a protected One-to-one relationship (Neal Todd) * Added labels to snippet bulk edit checkboxes for screen reader users (Martey Dodoo) * Middleware responses during page preview are now properly returned to the user (Matt Westcott) + * Default text of page links in rich text uses the public page title rather than the admin display title (Andy Chosak) Upgrade considerations diff --git a/wagtail/admin/templates/wagtailadmin/pages/listing/_page_title_choose.html b/wagtail/admin/templates/wagtailadmin/pages/listing/_page_title_choose.html index 5104862957..06366e9753 100644 --- a/wagtail/admin/templates/wagtailadmin/pages/listing/_page_title_choose.html +++ b/wagtail/admin/templates/wagtailadmin/pages/listing/_page_title_choose.html @@ -8,7 +8,7 @@ Expects a variable 'page', the page instance.
{% if page.can_choose %} - {{ page.get_admin_display_title }} + {{ page.get_admin_display_title }} {% else %} {{ page.get_admin_display_title }} {% endif %} diff --git a/wagtail/admin/tests/test_page_chooser.py b/wagtail/admin/tests/test_page_chooser.py index f19ab651a4..b8a9583d41 100644 --- a/wagtail/admin/tests/test_page_chooser.py +++ b/wagtail/admin/tests/test_page_chooser.py @@ -208,7 +208,13 @@ class TestChooserBrowseChild(TestCase, WagtailTestUtils): self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'wagtailadmin/chooser/browse.html') - self.assertInHTML("foobarbaz (simple page)", response.json().get('html')) + html = response.json().get('html') + self.assertInHTML("foobarbaz (simple page)", html) + + # The data-title attribute should not use the custom admin display title, + # because JS code that uses that attribute (e.g. the rich text editor) + # should use the real page title. + self.assertIn('data-title="foobarbaz"', html) def test_parent_with_admin_display_title(self): # Add another child under child_page so it renders a chooser list