Render breadcrumbs in page usage view

pull/11758/head
Sage Abdullah 2024-03-08 16:13:41 +00:00 zatwierdzone przez LB (Ben Johnston)
rodzic a388e57c1c
commit c6bb19d823
2 zmienionych plików z 34 dodań i 2 usunięć

Wyświetl plik

@ -8,9 +8,13 @@ from wagtail.test.testapp.models import (
SimplePage, SimplePage,
) )
from wagtail.test.utils import WagtailTestUtils 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): def setUp(self):
self.user = self.login() self.user = self.login()
self.root_page = Page.objects.get(id=2) self.root_page = Page.objects.get(id=2)
@ -24,7 +28,7 @@ class TestPageUsage(WagtailTestUtils, TestCase):
page.save_revision().publish() page.save_revision().publish()
self.page = SimplePage.objects.get(id=page.id) 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,)) usage_url = reverse("wagtailadmin_pages:usage", args=(self.page.id,))
response = self.client.get(usage_url) response = self.client.get(usage_url)
@ -33,6 +37,27 @@ class TestPageUsage(WagtailTestUtils, TestCase):
self.assertContains(response, "Usage") self.assertContains(response, "Usage")
self.assertContains(response, "Hello world!") 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): def test_has_private_usage(self):
PageChooserModel.objects.create(page=self.page) PageChooserModel.objects.create(page=self.page)
usage_url = reverse("wagtailadmin_pages:usage", args=(self.page.id,)) usage_url = reverse("wagtailadmin_pages:usage", args=(self.page.id,))

Wyświetl plik

@ -4,6 +4,7 @@ from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.http import Http404 from django.http import Http404
from django.urls import reverse from django.urls import reverse
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from wagtail.admin.ui.tables import Column, DateColumn from wagtail.admin.ui.tables import Column, DateColumn
@ -15,6 +16,7 @@ from wagtail.admin.ui.tables.pages import (
) )
from wagtail.admin.views import generic from wagtail.admin.views import generic
from wagtail.admin.views.generic.base import BaseListingView 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 from wagtail.models import Page
@ -76,8 +78,13 @@ class UsageView(generic.UsageView):
pk_url_kwarg = "page_id" pk_url_kwarg = "page_id"
header_icon = "doc-empty-inverse" header_icon = "doc-empty-inverse"
usage_url_name = "wagtailadmin_pages:usage" usage_url_name = "wagtailadmin_pages:usage"
_show_breadcrumbs = True
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
if not self.object.permissions_for_user(request.user).can_edit(): if not self.object.permissions_for_user(request.user).can_edit():
raise PermissionDenied raise PermissionDenied
return super().dispatch(request, *args, **kwargs) return super().dispatch(request, *args, **kwargs)
@cached_property
def breadcrumbs_items(self):
return get_breadcrumbs_items_for_page(self.object, self.request.user)