2020-08-16 19:24:31 +02:00
|
|
|
from django.contrib.syndication.views import Feed
|
|
|
|
|
2021-03-04 18:48:48 +01:00
|
|
|
from articles.models import Article, Tag
|
2020-08-16 19:24:31 +02:00
|
|
|
from blog import settings
|
|
|
|
|
|
|
|
|
|
|
|
class CompleteFeed(Feed):
|
2020-12-03 21:34:40 +01:00
|
|
|
FEED_LIMIT = 15
|
2021-03-04 19:33:43 +01:00
|
|
|
title = settings.BLOG["title"]
|
2020-08-16 19:24:31 +02:00
|
|
|
link = settings.BLOG["base_url"]
|
|
|
|
description = settings.BLOG["description"]
|
|
|
|
|
2021-03-04 18:48:48 +01:00
|
|
|
def get_queryset(self, obj):
|
2020-12-24 17:49:47 +01:00
|
|
|
return Article.objects.filter(status=Article.PUBLISHED).order_by(
|
2020-08-16 19:24:31 +02:00
|
|
|
"-published_at"
|
2021-03-04 18:48:48 +01:00
|
|
|
)
|
2020-08-16 19:24:31 +02:00
|
|
|
|
2021-03-04 18:48:48 +01:00
|
|
|
def items(self, obj):
|
|
|
|
return self.get_queryset(obj)[: self.FEED_LIMIT]
|
2020-08-16 19:24:31 +02:00
|
|
|
|
|
|
|
def item_description(self, item: Article):
|
2020-12-28 08:04:28 +01:00
|
|
|
return item.get_formatted_content
|
2020-08-16 19:24:31 +02:00
|
|
|
|
|
|
|
def item_pubdate(self, item: Article):
|
|
|
|
return item.published_at
|
2021-03-04 18:48:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TagFeed(CompleteFeed):
|
|
|
|
def get_object(self, request, *args, **kwargs):
|
|
|
|
return Tag.objects.get(slug=kwargs.get("slug"))
|
|
|
|
|
|
|
|
def get_queryset(self, tag):
|
|
|
|
return super().get_queryset(tag).filter(tags=tag)
|
2021-03-04 19:33:43 +01:00
|
|
|
|
|
|
|
def title(self, tag):
|
|
|
|
return tag.get_feed_title()
|
|
|
|
|
|
|
|
def link(self, tag):
|
|
|
|
return tag.get_absolute_url()
|