summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauréline Guérin <zebuline@entrouvert.com>2019-10-23 15:37:10 (GMT)
committerLauréline Guérin <zebuline@entrouvert.com>2019-11-03 16:28:17 (GMT)
commit45309fd524fc6fb7459f8d2d0831b0f51f9c3d2f (patch)
tree32dac9049b7bdae98a9b8eeb0e065898313dcb08
parentfbfeb64a8322f99413f87c73982002abd872f4e3 (diff)
downloadcombo-45309fd524fc6fb7459f8d2d0831b0f51f9c3d2f.zip
combo-45309fd524fc6fb7459f8d2d0831b0f51f9c3d2f.tar.gz
combo-45309fd524fc6fb7459f8d2d0831b0f51f9c3d2f.tar.bz2
pages: add a param check_visibility to next/previous methods (#12437)
-rw-r--r--combo/data/models.py8
-rw-r--r--tests/test_pages.py5
2 files changed, 9 insertions, 4 deletions
diff --git a/combo/data/models.py b/combo/data/models.py
index b18f3d0..728f0fa 100644
--- a/combo/data/models.py
+++ b/combo/data/models.py
@@ -281,22 +281,22 @@ class Page(models.Model):
tmpl.render(context, request)
return placeholders
- def get_next_page(self, user=None):
+ def get_next_page(self, user=None, check_visibility=True):
pages = Page.get_as_reordered_flat_hierarchy(Page.objects.all())
this_page = [x for x in pages if x.id == self.id][0]
pages = pages[pages.index(this_page)+1:]
for page in pages:
- if page.is_visible(user):
+ if not check_visibility or page.is_visible(user):
return page
return None
- def get_previous_page(self, user=None):
+ def get_previous_page(self, user=None, check_visibility=True):
pages = Page.get_as_reordered_flat_hierarchy(Page.objects.all())
pages.reverse()
this_page = [x for x in pages if x.id == self.id][0]
pages = pages[pages.index(this_page)+1:]
for page in pages:
- if page.is_visible(user):
+ if not check_visibility or page.is_visible(user):
return page
return None
diff --git a/tests/test_pages.py b/tests/test_pages.py
index b27db89..aa701bd 100644
--- a/tests/test_pages.py
+++ b/tests/test_pages.py
@@ -228,6 +228,11 @@ def test_next_previous():
page3.save()
assert page.get_next_page(None) is None
+ assert page.get_next_page(check_visibility=False).id == page2.pk
+ assert page2.get_next_page(check_visibility=False).id == page3.pk
+ assert page3.get_previous_page(check_visibility=False).id == page2.pk
+
+
def test_import_export_management_commands():
page = Page(title=u'foo', slug='foo', order=0)
page.save()