Skip to content

Commit

Permalink
Merge branch 'staging' into feature/twe-25-page-title
Browse files Browse the repository at this point in the history
  • Loading branch information
albinazs committed Jan 6, 2025
2 parents 8080cbb + 4b5dd84 commit 0314ef6
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tbx/blog/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BlogFeed(Feed):
description = "The latest news and views from Torchbox on the work we do, the web and the wider world"

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

def item_title(self, item):
return item.title
Expand Down
1 change: 1 addition & 0 deletions tbx/blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def blog_posts(self):
# Get list of blog pages that are descendants of this page
blog_posts = (
BlogPage.objects.live()
.public()
.descendant_of(self)
.distinct()
.prefetch_related(
Expand Down
38 changes: 36 additions & 2 deletions tbx/blog/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
from django.core.paginator import Page as PaginatorPage

from faker import Faker
from tbx.blog.factories import BlogIndexPageFactory, BlogPageFactory
from tbx.blog.models import BlogPage
from tbx.taxonomy.factories import SectorFactory, ServiceFactory
from wagtail.coreutils import get_dummy_request
from wagtail.models import PageViewRestriction
from wagtail.test.utils import WagtailPageTestCase

fake = Faker(["en_GB"])


class TestBlogIndexPageFactory(WagtailPageTestCase):
def test_create(self):
BlogIndexPageFactory()
@classmethod
def setUpTestData(cls):
cls.blog_index = BlogIndexPageFactory(title="The Torchbox Blog")
cls.blog_post = BlogPageFactory(title="The blog post", parent=cls.blog_index)
cls.private_blog_post = BlogPageFactory(
title="Private blog post", parent=cls.blog_index
)
cls.draft_blog_post = BlogPageFactory(
title="Draft blog post", live=False, parent=cls.blog_index
)
PageViewRestriction.objects.create(
page=cls.private_blog_post,
restriction_type="password",
password="password123",
)

def test_get_context(self):
context = self.blog_index.get_context(get_dummy_request())
blog_posts = context["blog_posts"]
print("blog_posts")
print(blog_posts)
self.assertIsInstance(blog_posts, PaginatorPage)
self.assertEqual(blog_posts.object_list.first(), self.blog_post)

def test_blog_posts_property(self):
"""Checks that the blog_posts property returns public and published blog posts under the given blog index."""
another_blog = BlogIndexPageFactory(title="Tech blog")
BlogPageFactory(title="Tech blog", parent=another_blog)
self.assertQuerysetEqual(
self.blog_index.blog_posts, BlogPage.objects.filter(pk=self.blog_post.pk)
)


class TestBlogPageFactory(WagtailPageTestCase):
Expand Down
4 changes: 2 additions & 2 deletions tbx/core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def global_vars(request):
return {
"GOOGLE_TAG_MANAGER_ID": getattr(settings, "GOOGLE_TAG_MANAGER_ID", None),
"SEO_NOINDEX": settings.SEO_NOINDEX,
"ALLOWED_MODES": json.dumps(settings.ALLOWED_MODES),
"MODE": mode,
"COOKIE_POLICY_PAGE": ImportantPageSettings.for_request(
request
).cookie_policy_page,
"CARBON_EMISSIONS_PAGE": ImportantPageSettings.for_request(
request
).carbon_emissions_page,
"ALLOWED_MODES": json.dumps(settings.ALLOWED_MODES),
"MODE": mode,
"BASE_DOMAIN": settings.BASE_DOMAIN,
}
16 changes: 12 additions & 4 deletions tbx/core/templatetags/torchbox_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def get_googe_maps_key():

@register.simple_tag
def get_next_sibling_by_order(page):
sibling = page.get_next_siblings().live().first()
sibling = page.get_next_siblings().live().public().first()

if sibling:
return sibling.specific


@register.simple_tag
def get_prev_sibling_by_order(page):
sibling = page.get_prev_siblings().live().first()
sibling = page.get_prev_siblings().live().public().first()

if sibling:
return sibling.specific
Expand All @@ -37,7 +37,11 @@ def get_prev_sibling_by_order(page):
@register.simple_tag
def get_next_sibling_blog(page):
sibling = (
BlogPage.objects.filter(date__lt=page.date).order_by("-date").live().first()
BlogPage.objects.filter(date__lt=page.date)
.order_by("-date")
.live()
.public()
.first()
)
if sibling:
return sibling.specific
Expand All @@ -46,7 +50,11 @@ def get_next_sibling_blog(page):
@register.simple_tag
def get_prev_sibling_blog(page):
sibling = (
BlogPage.objects.filter(date__gt=page.date).order_by("-date").live().last()
BlogPage.objects.filter(date__gt=page.date)
.order_by("-date")
.live()
.public()
.last()
)
if sibling:
return sibling.specific
Expand Down
1 change: 1 addition & 0 deletions tbx/static_src/sass/config/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ $color--grey-10: #e6e6e6;
$color--grey-20: #ccc;
$color--grey-30: #b3b3b3;
$color--grey-40: #999;
$color--grey-45: #989b9b;
$color--grey-50: #808080;
$color--grey-60: #666;
$color--grey-70: #4d4d4d;
Expand Down
2 changes: 2 additions & 0 deletions tbx/work/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def related_works(self):
Q(related_sectors__in=sectors) | Q(related_services__in=services)
)
.live()
.public()
.distinct()
.order_by(F("date").desc(nulls_last=True))
.exclude(pk=self.pk)[:4]
Expand Down Expand Up @@ -379,6 +380,7 @@ def works(self):
pages = (
self.get_children()
.live()
.public()
.type(HistoricalWorkPage, WorkPage)
.specific()
.prefetch_related(
Expand Down
40 changes: 38 additions & 2 deletions tbx/work/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,51 @@
from django.core.paginator import Page as PaginatorPage

from tbx.taxonomy.factories import ServiceFactory
from tbx.work.factories import (
HistoricalWorkPageFactory,
WorkIndexPageFactory,
WorkPageFactory,
)
from tbx.work.models import WorkPage
from wagtail.coreutils import get_dummy_request
from wagtail.models import PageViewRestriction
from wagtail.test.utils import WagtailPageTestCase


class TestWorkIndexPageFactory(WagtailPageTestCase):
def test_create(self):
WorkIndexPageFactory()
# def test_create(self):
# WorkIndexPageFactory()
@classmethod
def setUpTestData(cls):
cls.work_index = WorkIndexPageFactory(title="Our work")
cls.work_page = WorkPageFactory(title="Work page", parent=cls.work_index)
cls.private_work_page = WorkPageFactory(
title="Private work page", parent=cls.work_index
)
cls.draft_work_page = WorkPageFactory(
title="Draft work page", live=False, parent=cls.work_index
)
PageViewRestriction.objects.create(
page=cls.private_work_page,
restriction_type="password",
password="password123",
)

def test_get_context(self):
context = self.work_index.get_context(get_dummy_request())
work_pages = context["works"]
print("work_pages")
print(work_pages)
self.assertIsInstance(work_pages, PaginatorPage)
self.assertEqual(work_pages[0]["title"], self.work_page.title)

def test_works_property(self):
"""Checks that the works property returns public and published work pages under the given work index."""
another_work_index = WorkIndexPageFactory(title="Another work index")
WorkPageFactory(title="Another work page", parent=another_work_index)
self.assertQuerysetEqual(
self.work_index.works, WorkPage.objects.filter(pk=self.work_page.pk)
)


class TestHistoricalWorkPageFactory(WagtailPageTestCase):
Expand Down

0 comments on commit 0314ef6

Please sign in to comment.