kopia lustrzana https://github.com/wagtail/wagtail
Exclude root pages from `ModelAdmin`s (#7213)
Previously, this would fail, as `user_can_copy_obj` doesn't handle root pages. Root pages also are special in a number of ways, and handling copying is tricky and non-obvious. If someone needs to show root pages (for some reason), they'll have to special case them themselves.pull/7262/head
rodzic
5808a49407
commit
d5b955b0e4
docs/releases
wagtail
contrib/modeladmin
tests/modeladmintest
|
@ -18,6 +18,7 @@ Changelog
|
|||
* Fix: Snippet admin urls are now namespaced to avoid ambiguity with the primary key component of the url (Matt Westcott)
|
||||
* Fix: Save order of promoted search results (Hardcodd)
|
||||
* Fix: Prevent error on copying pages with ClusterTaggableManager relations and multi-level inheritance (Chris Pollard)
|
||||
* Fix: Prevent failure on root page when registering the Page model with ModelAdmin (Jake Howard)
|
||||
|
||||
|
||||
2.13.2 (17.06.2021)
|
||||
|
|
|
@ -518,6 +518,7 @@ Contributors
|
|||
* hardcodd
|
||||
* Chris Pollard
|
||||
* Godswill Melford
|
||||
* Jake Howard
|
||||
|
||||
Translators
|
||||
===========
|
||||
|
|
|
@ -29,6 +29,7 @@ Bug fixes
|
|||
* Prevent “Forgotten password” link from overlapping with field on mobile devices (Helen Chapman)
|
||||
* Snippet admin urls are now namespaced to avoid ambiguity with the primary key component of the url (Matt Westcott)
|
||||
* Prevent error on copying pages with ClusterTaggableManager relations and multi-level inheritance (Chris Pollard)
|
||||
* Prevent failure on root page when registering the Page model with ModelAdmin (Jake Howard)
|
||||
|
||||
Upgrade considerations
|
||||
======================
|
||||
|
|
|
@ -240,6 +240,9 @@ class ModelAdmin(WagtailRegisterable):
|
|||
ordering = self.get_ordering(request)
|
||||
if ordering:
|
||||
qs = qs.order_by(*ordering)
|
||||
if self.is_pagemodel:
|
||||
# If we're listing pages, exclude the root page
|
||||
qs = qs.exclude(depth=1)
|
||||
return qs
|
||||
|
||||
def get_search_fields(self, request):
|
||||
|
|
|
@ -54,6 +54,14 @@ class TestIndexView(TestCase, WagtailTestUtils):
|
|||
# There should still be four results
|
||||
self.assertEqual(response.context['result_count'], 4)
|
||||
|
||||
def test_using_core_page(self):
|
||||
# The core page is slightly different to other pages, so exclude it
|
||||
response = self.client.get('/admin/wagtailcore/page/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
root_page = Page.objects.get(depth=1)
|
||||
self.assertNotIn(root_page, response.context['paginator'].object_list)
|
||||
|
||||
|
||||
class TestExcludeFromExplorer(TestCase, WagtailTestUtils):
|
||||
fixtures = ['modeladmintest_test.json']
|
||||
|
@ -188,6 +196,12 @@ class TestEditView(TestCase, WagtailTestUtils):
|
|||
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
def test_using_core_page(self):
|
||||
# The core page is slightly different to other pages, so exclude it
|
||||
root_page = Page.objects.get(depth=1)
|
||||
response = self.client.get('/admin/wagtailcore/page/{}/'.format(root_page.id))
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
|
||||
class TestDeleteView(TestCase, WagtailTestUtils):
|
||||
fixtures = ['test_specific.json']
|
||||
|
|
|
@ -3,6 +3,7 @@ from wagtail.contrib.modeladmin.helpers import WagtailBackendSearchHandler
|
|||
from wagtail.contrib.modeladmin.options import (
|
||||
ModelAdmin, ModelAdminGroup, ThumbnailMixin, modeladmin_register)
|
||||
from wagtail.contrib.modeladmin.views import CreateView, EditView, IndexView
|
||||
from wagtail.core.models import Page
|
||||
from wagtail.tests.testapp.models import BusinessChild, EventPage, SingleEventPage
|
||||
|
||||
from .forms import PublisherModelAdminForm
|
||||
|
@ -171,6 +172,11 @@ class RelatedLinkAdmin(ModelAdmin):
|
|||
menu_label = "Related Links"
|
||||
|
||||
|
||||
class PageAdmin(ModelAdmin):
|
||||
model = Page
|
||||
menu_label = "Page"
|
||||
|
||||
|
||||
modeladmin_register(AuthorModelAdmin)
|
||||
modeladmin_register(BookModelAdmin)
|
||||
modeladmin_register(TokenModelAdmin)
|
||||
|
@ -182,3 +188,4 @@ modeladmin_register(FriendAdmin)
|
|||
modeladmin_register(VisitorAdmin)
|
||||
modeladmin_register(ContributorAdmin)
|
||||
modeladmin_register(RelatedLinkAdmin)
|
||||
modeladmin_register(PageAdmin)
|
||||
|
|
Ładowanie…
Reference in New Issue