diff --git a/opentech/public/news/views.py b/opentech/public/news/views.py index 5e1929eac8a9c662eab2bf3f20e4822ebbdf8cb4..7e9c7ef378cce4fe9a836817cb642a76a2347a11 100644 --- a/opentech/public/news/views.py +++ b/opentech/public/news/views.py @@ -1,4 +1,5 @@ from django.contrib.syndication.views import Feed +from django.db.models.functions import Coalesce from wagtail.core.models import Site @@ -14,7 +15,7 @@ class NewsFeed(Feed): description = news_feed_settings.news_description def items(self): - return NewsPage.objects.live().order_by('-first_published_at')[:20] + return NewsPage.objects.live().public().annotate(date=Coalesce('publication_date', 'first_published_at')).order_by('-date')[:20] def item_title(self, item): return item.title @@ -26,7 +27,7 @@ class NewsFeed(Feed): return item.display_date -class NewsTypesFeed(Feed): +class NewsTypesFeed(NewsFeed): site = Site.objects.get(is_default_site=True) news_feed_settings = NewsFeedSettings.for_site(site=site) news_index = NewsIndex.objects.first() @@ -44,13 +45,4 @@ class NewsTypesFeed(Feed): return self.news_feed_settings.news_per_type_description.format(news_type=obj) def items(self, obj): - return NewsPage.objects.live().filter(news_types__news_type=obj).order_by('-first_published_at')[:20] - - def item_title(self, item): - return item.title - - def item_description(self, item): - return item.body - - def item_pubdate(self, item): - return item.display_date + return NewsPage.objects.live().public().filter(news_types__news_type=obj).annotate(date=Coalesce('publication_date', 'first_published_at')).order_by('-date')[:20]