Skip to content
Snippets Groups Projects
Commit 255b8ff1 authored by Fredrik Jonsson's avatar Fredrik Jonsson
Browse files

Inherit from NewsFeed to avoid duplication and use Coalesce to order_by...

Inherit from NewsFeed to avoid duplication and use Coalesce to order_by publication_date if present.
parent a5ee3e5f
No related branches found
No related tags found
No related merge requests found
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]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment