Skip to content

Commit

Permalink
Render breadcrumbs in page usage view
Browse files Browse the repository at this point in the history
  • Loading branch information
laymonage authored and lb- committed Mar 13, 2024
1 parent a388e57 commit c6bb19d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
29 changes: 27 additions & 2 deletions wagtail/admin/tests/pages/test_page_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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,))
Expand Down
7 changes: 7 additions & 0 deletions wagtail/admin/views/pages/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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)

0 comments on commit c6bb19d

Please sign in to comment.