Unify page feed implementations

No need for a separate class just to handle blog publish dates
This commit is contained in:
Jake Howard 2023-11-29 14:17:22 +00:00
parent 7127afbc94
commit a8cd2742ab
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 5 additions and 31 deletions

View file

@ -1,4 +1,4 @@
from typing import Any, Optional, Type from typing import Any, Optional
from django.contrib.postgres.search import TrigramSimilarity from django.contrib.postgres.search import TrigramSimilarity
from django.db import models from django.db import models
@ -12,7 +12,6 @@ from wagtailautocomplete.edit_handlers import AutocompletePanel
from website.common.models import BaseContentPage, BaseListingPage from website.common.models import BaseContentPage, BaseListingPage
from website.common.utils import TocEntry from website.common.utils import TocEntry
from website.common.views import ContentPageFeed
from website.contrib.singleton_page.utils import SingletonPageCache from website.contrib.singleton_page.utils import SingletonPageCache
@ -37,12 +36,6 @@ class BlogPostListPage(BaseListingPage):
.order_by("-date", "title") .order_by("-date", "title")
) )
@property
def feed_class(self) -> Type[ContentPageFeed]:
from .views import BlogPostPageFeed
return BlogPostPageFeed
@cached_property @cached_property
def tag_list_page_url(self) -> Optional[str]: def tag_list_page_url(self) -> Optional[str]:
return SingletonPageCache.get_url(BlogPostTagListPage) return SingletonPageCache.get_url(BlogPostTagListPage)
@ -132,12 +125,6 @@ class BlogPostTagPage(BaseListingPage):
blog_list_page = BlogPostListPage.objects.get() blog_list_page = BlogPostListPage.objects.get()
return blog_list_page.get_listing_pages().filter(tags=self) return blog_list_page.get_listing_pages().filter(tags=self)
@property
def feed_class(self) -> Type[ContentPageFeed]:
from .views import BlogPostPageFeed
return BlogPostPageFeed
class BlogPostCollectionListPage(BaseListingPage): class BlogPostCollectionListPage(BaseListingPage):
subpage_types: list[Any] = [] subpage_types: list[Any] = []
@ -166,9 +153,3 @@ class BlogPostCollectionPage(BaseListingPage):
.public() .public()
.order_by("-date", "title") .order_by("-date", "title")
) )
@property
def feed_class(self) -> Type[ContentPageFeed]:
from .views import BlogPostPageFeed
return BlogPostPageFeed

View file

@ -1,10 +0,0 @@
from datetime import datetime, time
from website.common.views import ContentPageFeed
from .models import BlogPostPage
class BlogPostPageFeed(ContentPageFeed):
def item_pubdate(self, item: BlogPostPage) -> datetime:
return datetime.combine(item.date, time())

View file

@ -5,6 +5,7 @@ class CustomFeed(DefaultFeed):
""" """
A custom feed generator with additional features. A custom feed generator with additional features.
""" """
def __init__(self, request, **kwargs): def __init__(self, request, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self.request = request self.request = request

View file

@ -1,4 +1,4 @@
from datetime import datetime from datetime import datetime, time
from typing import Any, Optional from typing import Any, Optional
from django.contrib.syndication.views import Feed from django.contrib.syndication.views import Feed
@ -114,6 +114,8 @@ class AllPagesFeed(Feed):
return item.get_full_url(request=self.request) + "?utm_medium=rss" return item.get_full_url(request=self.request) + "?utm_medium=rss"
def item_pubdate(self, item: BasePage) -> datetime: def item_pubdate(self, item: BasePage) -> datetime:
if item_date := item.date:
return datetime.combine(item_date, time())
return item.first_published_at return item.first_published_at
def item_updateddate(self, item: BasePage) -> datetime: def item_updateddate(self, item: BasePage) -> datetime: