diff --git a/wagtail/tests/fixtures/test.json b/wagtail/tests/fixtures/test.json index 11b82d9f1..8e316ffd8 100644 --- a/wagtail/tests/fixtures/test.json +++ b/wagtail/tests/fixtures/test.json @@ -39,7 +39,7 @@ "model": "wagtailcore.page", "fields": { "title": "Events", - "numchild": 3, + "numchild": 4, "show_in_menus": true, "live": true, "depth": 3, @@ -186,6 +186,34 @@ } }, +{ + "pk": 9, + "model": "wagtailcore.page", + "fields": { + "title": "Ameristralia Day", + "numchild": 0, + "show_in_menus": true, + "live": true, + "depth": 4, + "content_type": ["tests", "eventpage"], + "path": "0001000100010004", + "url_path": "/home/events/final-event/", + "slug": "final-event", + "owner": 3 + } +}, +{ + "pk": 9, + "model": "tests.eventpage", + "fields": { + "date_from": "2015-04-22", + "audience": "public", + "location": "Ameristralia", + "body": "

come celebrate the independence of Ameristralia

", + "cost": "Free" + } +}, + { "pk": 1, "model": "tests.formfield", diff --git a/wagtail/wagtailcore/models.py b/wagtail/wagtailcore/models.py index 30ffc8a77..3b90e9c0e 100644 --- a/wagtail/wagtailcore/models.py +++ b/wagtail/wagtailcore/models.py @@ -649,6 +649,21 @@ class Page(MP_Node, ClusterableModel, Indexed): def get_siblings(self, inclusive=True): return Page.objects.sibling_of(self, inclusive) + def get_next_published_sibling(self): + next_sibling = self.get_next_sibling() + + while next_sibling and not next_sibling.live: + next_sibling = next_sibling.get_next_sibling() + + return next_sibling + + def get_prev_published_sibling(self): + prev_sibling = self.get_prev_sibling() + + while prev_sibling and not prev_sibling.live: + prev_sibling = prev_sibling.get_prev_sibling() + + return prev_sibling def get_navigation_menu_items(): # Get all pages that appear in the navigation menu: ones which have children, diff --git a/wagtail/wagtailcore/tests/test_page_queryset.py b/wagtail/wagtailcore/tests/test_page_queryset.py index 06f2c3e21..3db3bd5f8 100644 --- a/wagtail/wagtailcore/tests/test_page_queryset.py +++ b/wagtail/wagtailcore/tests/test_page_queryset.py @@ -254,3 +254,21 @@ class TestPageQuerySet(TestCase): # Check that the homepage is in the results homepage = Page.objects.get(url_path='/home/') self.assertTrue(pages.filter(id=homepage.id).exists()) + + def test_published_next(self): + events_index = Page.objects.get(url_path='/home/events/') + current_page = Page.objects.descendant_of(events_index).live().first() + + # All pages must be live + while current_page: + self.assertTrue(current_page.live) + current_page = current_page.get_next_published_sibling() + + def test_published_prev(self): + events_index = Page.objects.get(url_path='/home/events/') + current_page = Page.objects.descendant_of(events_index).live().last() + + # All pages must be live + while current_page: + self.assertTrue(current_page.live) + current_page = current_page.get_prev_published_sibling()