Call specific on parent page and breadcrumbs in page chooser

There was a small bug in the page chooser, where it would display
`page.title` instead of `get_admin_display_title` when loaded on with a
specified parent. This was because the page chooser was falling back to
Page.get_admin_display_title instead of the specific kind
pull/5195/head
Haydn Greatnews 2019-03-27 11:25:50 +13:00 zatwierdzone przez Matt Westcott
rodzic ba93dcef69
commit fa5c69ee00
6 zmienionych plików z 51 dodań i 1 usunięć

Wyświetl plik

@ -47,6 +47,7 @@ Changelog
* Fix: Prevent rich text editor crash when filtering copy-pasted content and the last block is to be removed, e.g. unsupported image (Thibaud Colas)
* Fix: Removing rich text links / documents now also works when the text selection is backwards (Thibaud Colas)
* Fix: Prevent the rich text editor from crashing when copy-paste filtering removes all of its content (Thibaud Colas)
* Fix: Page chooser now respects custom `get_admin_display_title` methods on parent page and breadcrumb (Haydn Greatnews)
2.4 (19.12.2018)

Wyświetl plik

@ -358,6 +358,7 @@ Contributors
* Wesley van Lee
* Md Arifin Ibne Matin
* Tom Usher
* Haydn Greatnews
Translators
===========

Wyświetl plik

@ -74,6 +74,7 @@ Bug fixes
* Prevent rich text editor crash when filtering copy-pasted content and the last block is to be removed, e.g. unsupported image (Thibaud Colas)
* Removing rich text links / documents now also works when the text selection is backwards (Thibaud Colas)
* Prevent the rich text editor from crashing when copy-paste filtering removes all of its content (Thibaud Colas)
* Page chooser now respects custom ``get_admin_display_title`` methods on parent page and breadcrumb (Haydn Greatnews)
Upgrade considerations

Wyświetl plik

@ -1,7 +1,7 @@
{% load i18n wagtailadmin_tags %}
<ul class="breadcrumb">
{% for page in page.get_ancestors %}
{% for page in page.get_ancestors.specific %}
{% if page.is_root %}
<li class="home"><a href="{% url 'wagtailadmin_choose_page_child' page.id %}{% querystring p=None %}" class="navigate-pages icon icon-home text-replace">{% trans 'Home' %}</a></li>
{% else %}

Wyświetl plik

@ -202,6 +202,51 @@ class TestChooserBrowseChild(TestCase, WagtailTestUtils):
response = self.get({'page_type': 'foo'})
self.assertEqual(response.status_code, 404)
def test_with_admin_display_title(self):
# Check the display of the child page title when it's a child
response = self.get({'page_type': 'wagtailcore.Page'})
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailadmin/chooser/browse.html')
self.assertInHTML("foobarbaz (simple page)", response.json().get('html'))
def test_parent_with_admin_display_title(self):
# Add another child under child_page so it renders a chooser list
leaf_page = SimplePage(title="quux", content="goodbye")
self.child_page.add_child(instance=leaf_page)
# Use the child page as the chooser parent
response = self.client.get(
reverse('wagtailadmin_choose_page_child', args=(self.child_page.id,)),
params={'page_type': 'wagtailcore.Page'}
)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailadmin/chooser/browse.html')
self.assertInHTML("foobarbaz (simple page)", response.json().get('html'))
self.assertInHTML("quux (simple page)", response.json().get('html'))
def test_admin_display_title_breadcrumb(self):
# Add another child under child_page so we get breadcrumbs
leaf_page = SimplePage(title="quux", content="goodbye")
self.child_page.add_child(instance=leaf_page)
# Use the leaf page as the chooser parent, so child is in the breadcrumbs
response = self.client.get(
reverse('wagtailadmin_choose_page_child', args=(leaf_page.id,))
)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailadmin/chooser/browse.html')
# Look for a link element in the breadcrumbs with the admin title
self.assertTagInHTML(
'<li><a href="/admin/choose-page/{page_id}/?" class="navigate-pages">{page_title}</a></li>'.format(
page_id=self.child_page.id,
page_title="foobarbaz (simple page)",
),
response.json().get('html')
)
def setup_pagination_test_data(self):
# Create lots of pages
for i in range(100):

Wyświetl plik

@ -87,6 +87,8 @@ def browse(request, parent_page_id=None):
all_desired_pages = filter_page_type(Page.objects.all(), desired_classes)
parent_page = all_desired_pages.first_common_ancestor()
parent_page = parent_page.specific
# Get children of parent page
pages = parent_page.get_children().specific()