2021-03-08 16:49:10 +00:00
|
|
|
""" serialize user's posts in rss feed """
|
2021-01-20 22:15:15 +00:00
|
|
|
|
|
|
|
from django.contrib.syndication.views import Feed
|
2021-08-09 14:38:43 +00:00
|
|
|
from django.template.loader import get_template
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
2021-10-06 17:37:09 +00:00
|
|
|
from bookwyrm import models
|
|
|
|
from .helpers import get_user_from_username
|
2021-01-20 22:15:15 +00:00
|
|
|
|
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-04-26 16:15:42 +00:00
|
|
|
"""serialize user's posts in rss feed"""
|
2021-03-08 16:49:10 +00:00
|
|
|
|
2021-05-20 23:12:24 +00:00
|
|
|
description_template = "rss/content.html"
|
2021-08-09 14:38:43 +00:00
|
|
|
|
|
|
|
def item_title(self, item):
|
|
|
|
"""render the item title"""
|
|
|
|
if hasattr(item, "pure_name") and item.pure_name:
|
|
|
|
return item.pure_name
|
|
|
|
title_template = get_template("snippets/status/header_content.html")
|
|
|
|
title = title_template.render({"status": item})
|
|
|
|
template = get_template("rss/title.html")
|
|
|
|
return template.render({"user": item.user, "item_title": title}).strip()
|
2021-01-20 22:15:15 +00:00
|
|
|
|
2021-06-18 21:12:56 +00:00
|
|
|
def get_object(self, request, username): # pylint: disable=arguments-differ
|
2021-04-26 16:15:42 +00:00
|
|
|
"""the user who's posts get serialized"""
|
2021-02-23 21:12:50 +00:00
|
|
|
return get_user_from_username(request.user, username)
|
2021-01-20 22:15:15 +00:00
|
|
|
|
|
|
|
def link(self, obj):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""link to the user's profile"""
|
2021-01-20 22:15:15 +00:00
|
|
|
return obj.local_path
|
|
|
|
|
|
|
|
def title(self, obj):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""title of the rss feed entry"""
|
2021-08-09 14:38:43 +00:00
|
|
|
return _(f"Status updates from {obj.display_name}")
|
2021-01-20 22:15:15 +00:00
|
|
|
|
|
|
|
def items(self, obj):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""the user's activity feed"""
|
2021-10-06 17:37:09 +00:00
|
|
|
return models.Status.privacy_filter(
|
2021-02-24 20:35:43 +00:00
|
|
|
obj,
|
2021-03-23 02:17:46 +00:00
|
|
|
privacy_levels=["public", "unlisted"],
|
2021-10-06 17:37:09 +00:00
|
|
|
).filter(user=obj)
|
2021-01-29 17:28:00 +00:00
|
|
|
|
2021-01-20 22:15:15 +00:00
|
|
|
def item_link(self, item):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""link to the status"""
|
2021-01-20 22:15:15 +00:00
|
|
|
return item.local_path
|