This repository has been archived on 2023-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
python-blog/articles/views/feeds.py

40 lines
1 KiB
Python
Raw Normal View History

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):
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):
2021-04-10 15:41:50 +02:00
return item.get_formatted_content_for_rss
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()