0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-24 10:58:52 +01:00

Merge pull request #329 from kaedroho/new-queryset-methods

Added in_menu and not_in_menu methods to PageQuerySet
This commit is contained in:
Karl Hobley 2014-06-27 11:46:53 +01:00
commit a445877c21
4 changed files with 37 additions and 0 deletions

View File

@ -17,6 +17,7 @@ Changelog
* 'image' tag now accepts extra keyword arguments to be output as attributes on the img tag
* 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
* Fix: Animated GIFs are now coalesced before resizing
* Fix: Wand backend clones images before modifying them
* Fix: Admin breadcrumb now positioned correctly on mobile

View File

@ -135,6 +135,12 @@ class PageManager(models.Manager):
def not_live(self):
return self.get_queryset().not_live()
def in_menu(self):
return self.get_queryset().in_menu()
def not_in_menu(self):
return self.get_queryset().not_in_menu()
def page(self, other):
return self.get_queryset().page(other)

View File

@ -16,6 +16,15 @@ class PageQuerySet(MP_NodeQuerySet):
def not_live(self):
return self.exclude(self.live_q())
def in_menu_q(self):
return Q(show_in_menus=True)
def in_menu(self):
return self.filter(self.in_menu_q())
def not_in_menu(self):
return self.exclude(self.in_menu_q())
def page_q(self, other):
return Q(id=other.id)

View File

@ -34,6 +34,27 @@ class TestPageQuerySet(TestCase):
event = Page.objects.get(url_path='/home/events/someone-elses-event/')
self.assertTrue(pages.filter(id=event.id).exists())
def test_in_menu(self):
pages = Page.objects.in_menu()
# All pages must be be in the menus
for page in pages:
self.assertTrue(page.show_in_menus)
# Check that the events index is in the results
events_index = Page.objects.get(url_path='/home/events/')
self.assertTrue(pages.filter(id=events_index.id).exists())
def test_not_in_menu(self):
pages = Page.objects.not_in_menu()
# All pages must not be in menus
for page in pages:
self.assertFalse(page.show_in_menus)
# Check that the root page is in the results
self.assertTrue(pages.filter(id=1).exists())
def test_page(self):
homepage = Page.objects.get(url_path='/home/')
pages = Page.objects.page(homepage)