summaryrefslogtreecommitdiffstats
path: root/users/views
diff options
context:
space:
mode:
authorAndrew Godwin2022-12-04 08:20:50 -0700
committerAndrew Godwin2022-12-04 08:20:50 -0700
commitec1848e0956c467f264614037ad53b26e99086f6 (patch)
tree60b8ad77751b35a2631121147a2d8a284e0d96f2 /users/views
parent6ce05296b01b1bd177e93b5ea3745fba5a5ff8f2 (diff)
downloadtakahe-ec1848e0956c467f264614037ad53b26e99086f6.tar.gz
takahe-ec1848e0956c467f264614037ad53b26e99086f6.tar.bz2
takahe-ec1848e0956c467f264614037ad53b26e99086f6.zip
Adding RSS feeds for local identities
Diffstat (limited to 'users/views')
-rw-r--r--users/views/identity.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/users/views/identity.py b/users/views/identity.py
index 1f75a0a..6cfcff9 100644
--- a/users/views/identity.py
+++ b/users/views/identity.py
@@ -2,6 +2,7 @@ import string
from django import forms
from django.contrib.auth.decorators import login_required
+from django.contrib.syndication.views import Feed
from django.core import validators
from django.http import Http404, JsonResponse
from django.shortcuts import redirect
@@ -89,6 +90,47 @@ class ViewIdentity(ListView):
return context
+class IdentityFeed(Feed):
+ """
+ Serves a local user's Public posts as an RSS feed
+ """
+
+ def get_object(self, request, handle):
+ return by_handle_or_404(
+ request,
+ handle,
+ local=True,
+ )
+
+ def title(self, identity: Identity):
+ return identity.name
+
+ def description(self, identity: Identity):
+ return f"Public posts from @{identity.handle}"
+
+ def link(self, identity: Identity):
+ return identity.absolute_profile_uri()
+
+ def items(self, identity: Identity):
+ return (
+ identity.posts.filter(
+ visibility=Post.Visibilities.public,
+ )
+ .select_related("author")
+ .prefetch_related("attachments")
+ .order_by("-created")
+ )
+
+ def item_description(self, item: Post):
+ return item.safe_content_remote()
+
+ def item_link(self, item: Post):
+ return item.absolute_object_uri()
+
+ def item_pubdate(self, item: Post):
+ return item.published
+
+
@method_decorator(identity_required, name="dispatch")
class ActionIdentity(View):
def post(self, request, handle):