From a8cd2742ab8684691d61b9e291ab702df8ffec2f Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 29 Nov 2023 14:17:22 +0000 Subject: [PATCH] Unify page feed implementations No need for a separate class just to handle blog publish dates --- website/blog/models.py | 21 +-------------------- website/blog/views.py | 10 ---------- website/common/feed_generators.py | 1 + website/common/views.py | 4 +++- 4 files changed, 5 insertions(+), 31 deletions(-) delete mode 100644 website/blog/views.py diff --git a/website/blog/models.py b/website/blog/models.py index acec431..dd8289b 100644 --- a/website/blog/models.py +++ b/website/blog/models.py @@ -1,4 +1,4 @@ -from typing import Any, Optional, Type +from typing import Any, Optional from django.contrib.postgres.search import TrigramSimilarity 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.utils import TocEntry -from website.common.views import ContentPageFeed from website.contrib.singleton_page.utils import SingletonPageCache @@ -37,12 +36,6 @@ class BlogPostListPage(BaseListingPage): .order_by("-date", "title") ) - @property - def feed_class(self) -> Type[ContentPageFeed]: - from .views import BlogPostPageFeed - - return BlogPostPageFeed - @cached_property def tag_list_page_url(self) -> Optional[str]: return SingletonPageCache.get_url(BlogPostTagListPage) @@ -132,12 +125,6 @@ class BlogPostTagPage(BaseListingPage): blog_list_page = BlogPostListPage.objects.get() 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): subpage_types: list[Any] = [] @@ -166,9 +153,3 @@ class BlogPostCollectionPage(BaseListingPage): .public() .order_by("-date", "title") ) - - @property - def feed_class(self) -> Type[ContentPageFeed]: - from .views import BlogPostPageFeed - - return BlogPostPageFeed diff --git a/website/blog/views.py b/website/blog/views.py deleted file mode 100644 index bdbc07f..0000000 --- a/website/blog/views.py +++ /dev/null @@ -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()) diff --git a/website/common/feed_generators.py b/website/common/feed_generators.py index e8056ff..80bfe4f 100644 --- a/website/common/feed_generators.py +++ b/website/common/feed_generators.py @@ -5,6 +5,7 @@ class CustomFeed(DefaultFeed): """ A custom feed generator with additional features. """ + def __init__(self, request, **kwargs): super().__init__(**kwargs) self.request = request diff --git a/website/common/views.py b/website/common/views.py index d2a7721..5e4218e 100644 --- a/website/common/views.py +++ b/website/common/views.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, time from typing import Any, Optional 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" def item_pubdate(self, item: BasePage) -> datetime: + if item_date := item.date: + return datetime.combine(item_date, time()) return item.first_published_at def item_updateddate(self, item: BasePage) -> datetime: