kopia lustrzana https://github.com/wagtail/wagtail
Use specific page models on explorer page listing.
In particular, this ensures that any custom URL routes defined on the page model are respected by the 'live' link: https://groups.google.com/d/msg/wagtail/qAmI4HbJfCI/9fxvoCmMEQAJpull/2220/merge
rodzic
2c25ce153e
commit
a6647c33c8
|
@ -43,6 +43,7 @@ Changelog
|
|||
* Fix: StreamBlock HTML rendering now handles non-ASCII characters correctly on Python 2 (Mikalai Radchuk)
|
||||
* Fix: Fixed a bug preventing pages with a OneToOneField from being copied (Liam Brenner)
|
||||
* Fix: SASS compilation errors during Wagtail development no longer cause exit of Gulp process, instead throws error to console and continues (Thomas Winter)
|
||||
* Fix: Explorer page listing now uses specific page models, so that custom URL schemes defined on Page subclasses are respected
|
||||
|
||||
1.3.1 (05.01.2016)
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
@ -87,6 +87,7 @@ Bug fixes
|
|||
* StreamBlock HTML rendering now handles non-ASCII characters correctly on Python 2 (Mikalai Radchuk)
|
||||
* Fixed a bug preventing pages with a ``OneToOneField`` from being copied (Liam Brenner)
|
||||
* SASS compilation errors during Wagtail development no longer cause exit of Gulp process, instead throws error to console and continues (Thomas Winter)
|
||||
* Fix: Explorer page listing now uses specific page models, so that custom URL schemes defined on Page subclasses are respected
|
||||
|
||||
|
||||
Upgrade considerations
|
||||
|
|
|
@ -254,6 +254,23 @@ class SingleEventPage(EventPage):
|
|||
help_text="Short text to describe what is this action about"
|
||||
)
|
||||
|
||||
# Give this page model a custom URL routing scheme
|
||||
def get_url_parts(self):
|
||||
url_parts = super(SingleEventPage, self).get_url_parts()
|
||||
if url_parts is None:
|
||||
return None
|
||||
else:
|
||||
site_id, root_url, page_path = url_parts
|
||||
return (site_id, root_url, page_path + 'pointless-suffix/')
|
||||
|
||||
def route(self, request, path_components):
|
||||
if path_components == ['pointless-suffix']:
|
||||
# treat this as equivalent to a request for this page
|
||||
return super(SingleEventPage, self).route(request, [])
|
||||
else:
|
||||
# fall back to default routing rules
|
||||
return super(SingleEventPage, self).route(request, path_components)
|
||||
|
||||
SingleEventPage.content_panels = [FieldPanel('excerpt')] + EventPage.content_panels
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ from django.utils import timezone
|
|||
|
||||
from wagtail.tests.testapp.models import (
|
||||
SimplePage, FilePage, EventPage, EventPageCarouselItem,
|
||||
StandardIndex, StandardChild,
|
||||
SingleEventPage, StandardIndex, StandardChild,
|
||||
BusinessIndex, BusinessChild, BusinessSubIndex,
|
||||
TaggedPage, Advert, AdvertPlacement)
|
||||
from wagtail.tests.utils import WagtailTestUtils
|
||||
|
@ -206,6 +206,23 @@ class TestPageExplorer(TestCase, WagtailTestUtils):
|
|||
# Check that we got the last page
|
||||
self.assertEqual(response.context['pages'].number, response.context['pages'].paginator.num_pages)
|
||||
|
||||
def test_listing_uses_specific_models(self):
|
||||
# SingleEventPage has custom URL routing; the 'live' link in the listing
|
||||
# should show the custom URL, which requires us to use the specific version
|
||||
# of the class
|
||||
self.new_event = SingleEventPage(
|
||||
title="New event",
|
||||
location='the moon', audience='public',
|
||||
cost='free', date_from='2001-01-01',
|
||||
latest_revision_created_at=datetime(2016, 1, 1)
|
||||
)
|
||||
self.root_page.add_child(instance=self.new_event)
|
||||
|
||||
response = self.client.get(reverse('wagtailadmin_explore', args=(self.root_page.id, )))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
self.assertContains(response, '/new-event/pointless-suffix/')
|
||||
|
||||
|
||||
class TestPageExplorerSignposting(TestCase, WagtailTestUtils):
|
||||
fixtures = ['test.json']
|
||||
|
|
|
@ -72,6 +72,12 @@ def index(request, parent_page_id=None):
|
|||
# allow drag-and-drop reordering
|
||||
do_paginate = ordering != 'ord'
|
||||
|
||||
if do_paginate:
|
||||
# Retrieve pages in their most specific form.
|
||||
# Only do this for paginated listings, as this could potentially be a
|
||||
# very expensive operation when performed on a large queryset.
|
||||
pages = pages.specific()
|
||||
|
||||
# allow hooks to modify the queryset
|
||||
for hook in hooks.get_hooks('construct_explorer_page_queryset'):
|
||||
pages = hook(parent_page, pages, request)
|
||||
|
|
Ładowanie…
Reference in New Issue