kopia lustrzana https://github.com/wagtail/wagtail
Render breadcrumbs in page usage view
rodzic
a388e57c1c
commit
c6bb19d823
|
@ -8,9 +8,13 @@ from wagtail.test.testapp.models import (
|
|||
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 @@ class TestPageUsage(WagtailTestUtils, TestCase):
|
|||
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 @@ class TestPageUsage(WagtailTestUtils, TestCase):
|
|||
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,))
|
||||
|
|
|
@ -4,6 +4,7 @@ from django.contrib.contenttypes.models import ContentType
|
|||
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.ui.tables.pages import (
|
|||
)
|
||||
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)
|
||||
|
|
Ładowanie…
Reference in New Issue