moviewyrm/bookwyrm/views/rss_feed.py

39 lines
1.1 KiB
Python
Raw Normal View History

2021-01-29 17:28:00 +00:00
''' serialize user's posts in rss feed '''
2021-01-20 22:15:15 +00:00
from django.contrib.syndication.views import Feed
from .helpers import get_activity_feed, get_user_from_username
2021-01-29 17:28:00 +00:00
# pylint: disable=no-self-use, unused-argument
2021-01-20 22:15:15 +00:00
class RssFeed(Feed):
2021-01-29 17:28:00 +00:00
''' serialize user's posts in rss feed '''
description_template = 'snippets/rss_content.html'
title_template = 'snippets/rss_title.html'
2021-01-20 22:15:15 +00:00
def get_object(self, request, username):
2021-01-29 17:28:00 +00:00
''' the user who's posts get serialized '''
return get_user_from_username(request.user, username)
2021-01-20 22:15:15 +00:00
2021-01-29 17:28:00 +00:00
2021-01-20 22:15:15 +00:00
def link(self, obj):
2021-01-29 17:28:00 +00:00
''' link to the user's profile '''
2021-01-20 22:15:15 +00:00
return obj.local_path
2021-01-29 17:28:00 +00:00
2021-01-20 22:15:15 +00:00
def title(self, obj):
2021-01-29 17:28:00 +00:00
''' title of the rss feed entry '''
return f'Status updates from {obj.display_name}'
2021-01-20 22:15:15 +00:00
def items(self, obj):
2021-01-29 17:28:00 +00:00
''' the user's activity feed '''
return get_activity_feed(
2021-02-24 20:35:43 +00:00
obj,
privacy=['public', 'unlisted'],
queryset=obj.status_set.select_subclasses()
)
2021-01-29 17:28:00 +00:00
2021-01-20 22:15:15 +00:00
def item_link(self, item):
2021-01-29 17:28:00 +00:00
''' link to the status '''
2021-01-20 22:15:15 +00:00
return item.local_path