diff --git a/wagtail/admin/tests/pages/test_page_usage.py b/wagtail/admin/tests/pages/test_page_usage.py index 9f071876c61c..3d85229ae720 100644 --- a/wagtail/admin/tests/pages/test_page_usage.py +++ b/wagtail/admin/tests/pages/test_page_usage.py @@ -8,9 +8,13 @@ SimplePage, ) from wagtail.test.utils import WagtailTestUtils +from wagtail.test.utils.template_tests import AdminTemplateTestUtils -class TestPageUsage(WagtailTestUtils, TestCase): +class TestPageUsage(AdminTemplateTestUtils, WagtailTestUtils, TestCase): + # We don't show the "Home" breadcrumb item in page views + base_breadcrumb_items = [] + def setUp(self): self.user = self.login() self.root_page = Page.objects.get(id=2) @@ -24,7 +28,7 @@ def setUp(self): page.save_revision().publish() self.page = SimplePage.objects.get(id=page.id) - def test_no_usage(self): + def test_simple(self): usage_url = reverse("wagtailadmin_pages:usage", args=(self.page.id,)) response = self.client.get(usage_url) @@ -33,6 +37,27 @@ def test_no_usage(self): self.assertContains(response, "Usage") self.assertContains(response, "Hello world!") + items = [ + { + "url": reverse("wagtailadmin_explore_root"), + "label": "Root", + }, + { + "url": reverse("wagtailadmin_explore", args=(self.root_page.id,)), + "label": "Welcome to your new Wagtail site!", + }, + { + "url": reverse("wagtailadmin_explore", args=(self.page.id,)), + "label": "Hello world! (simple page)", + }, + { + "url": "", + "label": "Usage", + "sublabel": "Hello world! (simple page)", + }, + ] + self.assertBreadcrumbsItemsRendered(items, response.content) + def test_has_private_usage(self): PageChooserModel.objects.create(page=self.page) usage_url = reverse("wagtailadmin_pages:usage", args=(self.page.id,)) diff --git a/wagtail/admin/views/pages/usage.py b/wagtail/admin/views/pages/usage.py index 5d7c90299420..31094e8bc052 100644 --- a/wagtail/admin/views/pages/usage.py +++ b/wagtail/admin/views/pages/usage.py @@ -4,6 +4,7 @@ from django.core.exceptions import PermissionDenied from django.http import Http404 from django.urls import reverse +from django.utils.functional import cached_property from django.utils.translation import gettext_lazy as _ from wagtail.admin.ui.tables import Column, DateColumn @@ -15,6 +16,7 @@ ) from wagtail.admin.views import generic from wagtail.admin.views.generic.base import BaseListingView +from wagtail.admin.views.pages.utils import get_breadcrumbs_items_for_page from wagtail.models import Page @@ -76,8 +78,13 @@ class UsageView(generic.UsageView): pk_url_kwarg = "page_id" header_icon = "doc-empty-inverse" usage_url_name = "wagtailadmin_pages:usage" + _show_breadcrumbs = True def dispatch(self, request, *args, **kwargs): if not self.object.permissions_for_user(request.user).can_edit(): raise PermissionDenied return super().dispatch(request, *args, **kwargs) + + @cached_property + def breadcrumbs_items(self): + return get_breadcrumbs_items_for_page(self.object, self.request.user)