Skip to content

Commit b7d0a6b

Browse files
committed
Filter listings by whether the page is public
1 parent 03bc0e5 commit b7d0a6b

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

tbx/blog/feeds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class BlogFeed(Feed):
1414
description = "The latest news and views from Torchbox on the work we do, the web and the wider world"
1515

1616
def items(self):
17-
return BlogPage.objects.live().order_by("-date")[:10]
17+
return BlogPage.objects.live().public().order_by("-date")[:10]
1818

1919
def item_title(self, item):
2020
return item.title

tbx/blog/models.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
from modelcluster.fields import ParentalManyToManyField
1515
from tbx.core.blocks import StoryBlock
1616
from tbx.core.utils.fields import StreamField
17-
from tbx.core.utils.models import (
18-
ColourThemeMixin,
19-
NavigationFields,
20-
SocialFields,
21-
)
17+
from tbx.core.utils.models import ColourThemeMixin, NavigationFields, SocialFields
2218
from tbx.images.models import CustomImage
2319
from tbx.people.models import ContactMixin
2420
from tbx.taxonomy.models import Sector, Service
@@ -54,6 +50,7 @@ def blog_posts(self):
5450
# Get list of blog pages that are descendants of this page
5551
blog_posts = (
5652
BlogPage.objects.live()
53+
.public()
5754
.descendant_of(self)
5855
.distinct()
5956
.prefetch_related(

tbx/core/templatetags/torchbox_tags.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ def get_googe_maps_key():
2020

2121
@register.simple_tag
2222
def get_next_sibling_by_order(page):
23-
sibling = page.get_next_siblings().live().first()
23+
sibling = page.get_next_siblings().live().public().first()
2424

2525
if sibling:
2626
return sibling.specific
2727

2828

2929
@register.simple_tag
3030
def get_prev_sibling_by_order(page):
31-
sibling = page.get_prev_siblings().live().first()
31+
sibling = page.get_prev_siblings().live().public().first()
3232

3333
if sibling:
3434
return sibling.specific
@@ -37,7 +37,11 @@ def get_prev_sibling_by_order(page):
3737
@register.simple_tag
3838
def get_next_sibling_blog(page):
3939
sibling = (
40-
BlogPage.objects.filter(date__lt=page.date).order_by("-date").live().first()
40+
BlogPage.objects.filter(date__lt=page.date)
41+
.order_by("-date")
42+
.live()
43+
.public()
44+
.first()
4145
)
4246
if sibling:
4347
return sibling.specific
@@ -46,7 +50,11 @@ def get_next_sibling_blog(page):
4650
@register.simple_tag
4751
def get_prev_sibling_blog(page):
4852
sibling = (
49-
BlogPage.objects.filter(date__gt=page.date).order_by("-date").live().last()
53+
BlogPage.objects.filter(date__gt=page.date)
54+
.order_by("-date")
55+
.live()
56+
.public()
57+
.last()
5058
)
5159
if sibling:
5260
return sibling.specific

tbx/work/models.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
from modelcluster.fields import ParentalManyToManyField
1515
from tbx.core.blocks import StoryBlock
1616
from tbx.core.utils.fields import StreamField
17-
from tbx.core.utils.models import (
18-
ColourThemeMixin,
19-
NavigationFields,
20-
SocialFields,
21-
)
17+
from tbx.core.utils.models import ColourThemeMixin, NavigationFields, SocialFields
2218
from tbx.images.models import CustomImage
2319
from tbx.people.models import ContactMixin
2420
from tbx.taxonomy.models import Sector, Service
@@ -120,6 +116,7 @@ def related_works(self):
120116
Q(related_sectors__in=sectors) | Q(related_services__in=services)
121117
)
122118
.live()
119+
.public()
123120
.distinct()
124121
.order_by(F("date").desc(nulls_last=True))
125122
.exclude(pk=self.pk)[:4]
@@ -379,6 +376,7 @@ def works(self):
379376
pages = (
380377
self.get_children()
381378
.live()
379+
.public()
382380
.type(HistoricalWorkPage, WorkPage)
383381
.specific()
384382
.prefetch_related(

0 commit comments

Comments
 (0)