Make get_next/prev_siblings take an inclusive flag

pull/375/head^2^2
Karl Hobley 2014-06-27 11:33:05 +01:00
rodzic 8416af159a
commit e85e723f8f
2 zmienionych plików z 14 dodań i 4 usunięć

Wyświetl plik

@ -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,

Wyświetl plik

@ -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)