Create base content page rather than need mixin
This makes the subclassing much simpler, and removes type ignore hacks
This commit is contained in:
parent
489a212b7a
commit
8952f7eae5
4 changed files with 20 additions and 45 deletions
|
@ -11,11 +11,11 @@ from wagtail.admin.panels import FieldPanel
|
|||
from wagtail.contrib.routable_page.models import RoutablePageMixin, route
|
||||
from wagtail.query import PageQuerySet
|
||||
|
||||
from website.common.models import BaseContentMixin, BasePage
|
||||
from website.common.models import BaseContentPage
|
||||
from website.common.utils import TocEntry
|
||||
|
||||
|
||||
class BlogListPage(BaseContentMixin, RoutablePageMixin, BasePage): # type: ignore[misc]
|
||||
class BlogListPage(RoutablePageMixin, BaseContentPage):
|
||||
max_count = 1
|
||||
subpage_types = [
|
||||
"blog.BlogPostPage",
|
||||
|
@ -23,8 +23,6 @@ class BlogListPage(BaseContentMixin, RoutablePageMixin, BasePage): # type: igno
|
|||
"blog.BlogCollectionListPage",
|
||||
"blog.BlogCollectionPage",
|
||||
]
|
||||
content_panels = BasePage.content_panels + BaseContentMixin.content_panels
|
||||
search_fields = BasePage.search_fields + BaseContentMixin.search_fields
|
||||
|
||||
@cached_property
|
||||
def reading_time(self) -> int:
|
||||
|
@ -69,29 +67,24 @@ class BlogListPage(BaseContentMixin, RoutablePageMixin, BasePage): # type: igno
|
|||
)(request)
|
||||
|
||||
|
||||
class BlogPostPage(BaseContentMixin, BasePage): # type: ignore[misc]
|
||||
class BlogPostPage(BaseContentPage):
|
||||
subpage_types: list[Any] = []
|
||||
parent_page_types = [BlogListPage, "blog.BlogCollectionPage"]
|
||||
search_fields = BasePage.search_fields + BaseContentMixin.search_fields
|
||||
|
||||
tags = ParentalManyToManyField("blog.BlogPostTagPage", blank=True)
|
||||
date = models.DateField(default=timezone.now)
|
||||
|
||||
content_panels = (
|
||||
BasePage.content_panels
|
||||
+ BaseContentMixin.content_panels
|
||||
+ [FieldPanel("date"), FieldPanel("tags")]
|
||||
)
|
||||
content_panels = BaseContentPage.content_panels + [
|
||||
FieldPanel("date"),
|
||||
FieldPanel("tags"),
|
||||
]
|
||||
|
||||
|
||||
class BlogPostTagListPage(BaseContentMixin, BasePage): # type: ignore[misc]
|
||||
class BlogPostTagListPage(BaseContentPage):
|
||||
max_count = 1
|
||||
parent_page_types = [BlogListPage]
|
||||
subpage_types = ["blog.BlogPostTagPage"]
|
||||
|
||||
content_panels = BasePage.content_panels + BaseContentMixin.content_panels
|
||||
search_fields = BasePage.search_fields + BaseContentMixin.search_fields
|
||||
|
||||
@cached_property
|
||||
def table_of_contents(self) -> list[TocEntry]:
|
||||
return [TocEntry(page.title, page.slug, 0, []) for page in self.get_tags()]
|
||||
|
@ -105,13 +98,10 @@ class BlogPostTagListPage(BaseContentMixin, BasePage): # type: ignore[misc]
|
|||
return context
|
||||
|
||||
|
||||
class BlogPostTagPage(BaseContentMixin, RoutablePageMixin, BasePage): # type: ignore[misc]
|
||||
class BlogPostTagPage(RoutablePageMixin, BaseContentPage):
|
||||
subpage_types: list[Any] = []
|
||||
parent_page_types = [BlogPostTagListPage]
|
||||
|
||||
content_panels = BasePage.content_panels + BaseContentMixin.content_panels
|
||||
search_fields = BasePage.search_fields + BaseContentMixin.search_fields
|
||||
|
||||
@cached_property
|
||||
def table_of_contents(self) -> list[TocEntry]:
|
||||
return [
|
||||
|
@ -136,14 +126,11 @@ class BlogPostTagPage(BaseContentMixin, RoutablePageMixin, BasePage): # type: i
|
|||
)(request)
|
||||
|
||||
|
||||
class BlogCollectionListPage(BaseContentMixin, BasePage): # type: ignore[misc]
|
||||
class BlogCollectionListPage(BaseContentPage):
|
||||
subpage_types: list[Any] = []
|
||||
parent_page_types = [BlogListPage]
|
||||
max_count = 1
|
||||
|
||||
content_panels = BasePage.content_panels + BaseContentMixin.content_panels
|
||||
search_fields = BasePage.search_fields + BaseContentMixin.search_fields
|
||||
|
||||
@cached_property
|
||||
def table_of_contents(self) -> list[TocEntry]:
|
||||
return [
|
||||
|
@ -160,13 +147,10 @@ class BlogCollectionListPage(BaseContentMixin, BasePage): # type: ignore[misc]
|
|||
return context
|
||||
|
||||
|
||||
class BlogCollectionPage(BaseContentMixin, BasePage): # type: ignore[misc]
|
||||
class BlogCollectionPage(BaseContentPage):
|
||||
parent_page_types = [BlogListPage]
|
||||
subpage_types = [BlogPostPage]
|
||||
|
||||
content_panels = BasePage.content_panels + BaseContentMixin.content_panels
|
||||
search_fields = BasePage.search_fields + BaseContentMixin.search_fields
|
||||
|
||||
@cached_property
|
||||
def table_of_contents(self) -> list[TocEntry]:
|
||||
return [
|
||||
|
|
|
@ -37,7 +37,7 @@ class BasePage(Page):
|
|||
return self.get_ancestors().exclude(depth__lte=2)
|
||||
|
||||
|
||||
class BaseContentMixin(models.Model):
|
||||
class BaseContentPage(BasePage):
|
||||
subtitle = models.CharField(max_length=255, blank=True)
|
||||
hero_image = models.ForeignKey(
|
||||
get_image_model_string(), null=True, blank=True, on_delete=models.SET_NULL
|
||||
|
@ -47,14 +47,14 @@ class BaseContentMixin(models.Model):
|
|||
)
|
||||
body = StreamField(get_blocks(), blank=True, use_json_field=True)
|
||||
|
||||
content_panels = [
|
||||
content_panels = BasePage.content_panels + [
|
||||
FieldPanel("subtitle"),
|
||||
FieldPanel("hero_image"),
|
||||
FieldPanel("hero_unsplash_photo", widget=UnsplashPhotoChooser),
|
||||
FieldPanel("body"),
|
||||
]
|
||||
|
||||
search_fields = [
|
||||
search_fields = BasePage.search_fields + [
|
||||
index.SearchField("body"),
|
||||
index.SearchField("subtitle"),
|
||||
]
|
||||
|
@ -106,16 +106,11 @@ class BaseContentMixin(models.Model):
|
|||
return None
|
||||
|
||||
|
||||
class ContentPage(BasePage, BaseContentMixin): # type: ignore[misc]
|
||||
class ContentPage(BaseContentPage):
|
||||
subpage_types: list[Any] = []
|
||||
content_panels = BasePage.content_panels + BaseContentMixin.content_panels
|
||||
search_fields = BasePage.search_fields + BaseContentMixin.search_fields
|
||||
|
||||
|
||||
class ListingPage(BasePage, BaseContentMixin): # type: ignore[misc]
|
||||
content_panels = BasePage.content_panels + BaseContentMixin.content_panels
|
||||
search_fields = BasePage.search_fields + BaseContentMixin.search_fields
|
||||
|
||||
class ListingPage(BaseContentPage):
|
||||
def get_context(self, request: HttpRequest) -> dict:
|
||||
context = super().get_context(request)
|
||||
context["child_pages"] = (
|
||||
|
|
|
@ -6,7 +6,7 @@ from wagtail.admin.panels import FieldPanel
|
|||
from wagtail.search import index
|
||||
from wagtail.snippets.models import register_snippet
|
||||
|
||||
from website.common.models import BaseContentMixin, BasePage
|
||||
from website.common.models import BaseContentPage
|
||||
from website.common.utils import TocEntry
|
||||
|
||||
|
||||
|
@ -36,11 +36,9 @@ class OnlineAccount(models.Model, index.Indexed):
|
|||
return slugify(self.name)
|
||||
|
||||
|
||||
class ContactPage(BaseContentMixin, BasePage): # type: ignore[misc]
|
||||
class ContactPage(BaseContentPage):
|
||||
max_count = 1
|
||||
subpage_types: list = []
|
||||
content_panels = BasePage.content_panels + BaseContentMixin.content_panels
|
||||
search_fields = BasePage.search_fields + BaseContentMixin.search_fields
|
||||
|
||||
@cached_property
|
||||
def reading_time(self) -> int:
|
||||
|
|
|
@ -10,19 +10,17 @@ from wagtail.models import Page
|
|||
from wagtail.query import PageQuerySet
|
||||
from wagtail.search.utils import parse_query_string
|
||||
|
||||
from website.common.models import BaseContentMixin, BasePage
|
||||
from website.common.models import BaseContentPage
|
||||
from website.common.utils import TocEntry
|
||||
from website.home.models import HomePage
|
||||
|
||||
from .serializers import MIN_SEARCH_LENGTH, SearchParamsSerializer
|
||||
|
||||
|
||||
class SearchPage(BaseContentMixin, RoutablePageMixin, BasePage): # type: ignore[misc]
|
||||
class SearchPage(RoutablePageMixin, BaseContentPage):
|
||||
max_count = 1
|
||||
subpage_types: list = []
|
||||
parent_page_types = ["home.HomePage"]
|
||||
content_panels = BasePage.content_panels + BaseContentMixin.content_panels
|
||||
search_fields = BasePage.search_fields + BaseContentMixin.search_fields
|
||||
PAGE_SIZE = 15
|
||||
|
||||
@cached_property
|
||||
|
|
Loading…
Reference in a new issue