Merge branch 'pr/301'

Conflicts:
	CHANGELOG.txt
pull/375/head^2
Karl Hobley 2014-06-27 12:01:46 +01:00
commit 1671b2cfa8
4 zmienionych plików z 57 dodań i 1 usunięć

Wyświetl plik

@ -18,6 +18,7 @@ Changelog
* Added an 'attrs' property to image rendition objects to output src, width, height and alt attributes all in one go
* Added 'construct_whitelister_element_rules' hook for customising the HTML whitelist used when saving rich text fields
* Added 'in_menu' and 'not_in_menu' methods to PageQuerySet
* Added 'get_next_siblings' and 'get_prev_siblings' to Page
* Fix: Animated GIFs are now coalesced before resizing
* Fix: Wand backend clones images before modifying them
* Fix: Admin breadcrumb now positioned correctly on mobile

Wyświetl plik

@ -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": "<p>come celebrate the independence of Ameristralia</p>",
"cost": "Free"
}
},
{
"pk": 1,
"model": "tests.formfield",

Wyświetl plik

@ -651,6 +651,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, 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_navigation_menu_items():
# Get all pages that appear in the navigation menu: ones which have children,

Wyświetl plik

@ -224,3 +224,24 @@ class TestMovePage(TestCase):
christmas = events_index.get_children().get(slug='christmas')
self.assertEqual(christmas.depth, 5)
self.assertEqual(christmas.url_path, '/home/about-us/events/christmas/')
class TestPrevNextSiblings(TestCase):
fixtures = ['test.json']
def test_get_next_siblings(self):
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)