Add the concept of post collections

For things which are a fixed series (eg yearly repeats)
This commit is contained in:
Jake Howard 2022-07-16 15:45:57 +01:00
parent 2ae8ec7045
commit 6b96688adb
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 2033 additions and 3 deletions

File diff suppressed because it is too large Load diff

View file

@ -15,7 +15,12 @@ from website.common.utils import TocEntry
class BlogListPage(BaseContentMixin, BasePage): # type: ignore[misc]
max_count = 1
subpage_types = ["blog.BlogPostPage", "blog.BlogPostTagListPage"]
subpage_types = [
"blog.BlogPostPage",
"blog.BlogPostTagListPage",
"blog.BlogCollectionListPage",
"blog.BlogCollectionPage",
]
content_panels = BasePage.content_panels + BaseContentMixin.content_panels
@cached_property
@ -39,7 +44,9 @@ class BlogListPage(BaseContentMixin, BasePage): # type: ignore[misc]
return [TocEntry(post_month, post_month, 0, []) for post_month in post_months]
def get_blog_posts(self) -> PageQuerySet:
return BlogPostPage.objects.child_of(self).live() # type:ignore[attr-defined]
return BlogPostPage.objects.descendant_of( # type:ignore[attr-defined]
self
).live()
def get_context(self, request: HttpRequest) -> dict:
context = super().get_context(request)
@ -55,7 +62,7 @@ class BlogListPage(BaseContentMixin, BasePage): # type: ignore[misc]
class BlogPostPage(BaseContentMixin, BasePage): # type: ignore[misc]
subpage_types: list[Any] = []
parent_page_types = [BlogListPage]
parent_page_types = [BlogListPage, "blog.BlogCollectionPage"]
tags = ParentalManyToManyField("blog.BlogPostTagPage", blank=True)
date = models.DateField(default=timezone.now)
@ -109,3 +116,53 @@ class BlogPostTagPage(BaseContentMixin, BasePage): # type: ignore[misc]
context = super().get_context(request)
context["pages"] = self.get_blog_posts()
return context
class BlogCollectionListPage(BaseContentMixin, BasePage): # type: ignore[misc]
subpage_types: list[Any] = []
parent_page_types = [BlogListPage]
max_count = 1
content_panels = BasePage.content_panels + BaseContentMixin.content_panels
@cached_property
def table_of_contents(self) -> list[TocEntry]:
return [
TocEntry(page.title, page.slug, 0, []) for page in self.get_collections()
]
def get_collections(self) -> PageQuerySet:
blog_list_page = (
BlogListPage.objects.all().live().get() # type:ignore[attr-defined]
)
return BlogCollectionPage.objects.child_of( # type:ignore[attr-defined]
blog_list_page
).live()
def get_context(self, request: HttpRequest) -> dict:
context = super().get_context(request)
context["collections"] = self.get_collections()
return context
class BlogCollectionPage(BaseContentMixin, BasePage): # type: ignore[misc]
parent_page_types = [BlogListPage]
subpage_types = [BlogPostPage]
content_panels = BasePage.content_panels + BaseContentMixin.content_panels
@cached_property
def table_of_contents(self) -> list[TocEntry]:
return [
TocEntry(page.title, page.slug, 0, []) for page in self.get_blog_posts()
]
def get_blog_posts(self) -> PageQuerySet:
return BlogPostPage.objects.child_of( # type:ignore[attr-defined]
self
).order_by("-date")
def get_context(self, request: HttpRequest) -> dict:
context = super().get_context(request)
context["pages"] = self.get_blog_posts()
return context

View file

@ -0,0 +1,19 @@
{% extends "wagtail_base.html" %}
{% block content %}
{% include "common/hero.html" %}
{% if page.body_html %}
<section class="container content">
{{ page.body_html|safe }}
</section>
{% endif %}
<section class="container">
{% for collection in collections %}
{% include "common/listing-item.html" with page=collection %}
{% endfor %}
</section>
{% endblock content %}

View file

@ -0,0 +1,19 @@
{% extends "wagtail_base.html" %}
{% block content %}
{% include "common/hero.html" %}
{% if page.body_html %}
<section class="container content">
{{ page.body_html|safe }}
</section>
{% endif %}
<section class="container">
{% for page in pages %}
{% include "common/listing-item.html" %}
{% endfor %}
</section>
{% endblock content %}