kopia lustrzana https://github.com/wagtail/wagtail
Make get_next/prev_siblings take an inclusive flag
rodzic
8416af159a
commit
e85e723f8f
|
@ -645,11 +645,12 @@ class Page(MP_Node, ClusterableModel, Indexed):
|
|||
def get_siblings(self, inclusive=True):
|
||||
return Page.objects.sibling_of(self, inclusive)
|
||||
|
||||
def get_next_siblings(self):
|
||||
return self.get_siblings().filter(path__gt=self.path).order_by('path')
|
||||
def get_next_siblings(self, inclusive=False):
|
||||
return self.get_siblings(inclusive).filter(path__gte=self.path).order_by('path')
|
||||
|
||||
def get_prev_siblings(self, inclusive=False):
|
||||
return self.get_siblings(inclusive).filter(path__lte=self.path).order_by('-path')
|
||||
|
||||
def get_prev_siblings(self):
|
||||
return self.get_siblings().filter(path__lt=self.path).order_by('-path')
|
||||
|
||||
def get_navigation_menu_items():
|
||||
# Get all pages that appear in the navigation menu: ones which have children,
|
||||
|
|
|
@ -233,6 +233,15 @@ class TestPrevNextSiblings(TestCase):
|
|||
christmas_event = Page.objects.get(url_path='/home/events/christmas/')
|
||||
self.assertTrue(christmas_event.get_next_siblings().filter(url_path='/home/events/final-event/').exists())
|
||||
|
||||
def test_get_next_siblings_inclusive(self):
|
||||
christmas_event = Page.objects.get(url_path='/home/events/christmas/')
|
||||
|
||||
# First element must always be the current page
|
||||
self.assertEqual(christmas_event.get_next_siblings(inclusive=True).first(), christmas_event)
|
||||
|
||||
def test_get_prev_siblings(self):
|
||||
final_event = Page.objects.get(url_path='/home/events/final-event/')
|
||||
self.assertTrue(final_event.get_prev_siblings().filter(url_path='/home/events/christmas/').exists())
|
||||
|
||||
# First element must always be the current page
|
||||
self.assertEqual(final_event.get_prev_siblings(inclusive=True).first(), final_event)
|
||||
|
|
Ładowanie…
Reference in New Issue