from datetime import datetime, time from django.contrib.syndication.views import Feed from django.http import Http404 from .models import BlogPage, BlogIndexPage from django.utils.feedgenerator import Atom1Feed class RssBlogFeed(Feed): title = "Konstantin's Blog Feed" description = "A blog on independent software development, Swift, Elixir and more..." def link(self): root = BlogIndexPage.objects.live().public().first() if not root: raise Http404 return root.full_url def items(self): return BlogPage.objects.live().public().order_by("-first_published_at") def item_title(self, item): return item.title def item_description(self, item): return item.intro def item_link(self, item): return item.full_url def item_pubdate(self, item): return datetime.combine(item.date, time()) def item_author_name(self, item): author = item.authors.first() if not author: return None return author.name class AtomBlogFeed(RssBlogFeed): feed_type = Atom1Feed subtitle = RssBlogFeed.description