From d0d5c1534518691b3f5b259aac7461ca8652fc4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20I=C3=9Fbr=C3=BCcker?= Date: Sun, 17 Mar 2024 11:55:34 +0100 Subject: [PATCH] Add RSS feeds for shared bookmarks (#656) * Add shared bookmarks feed * Add public shared bookmarks feed --- bookmarks/feeds.py | 40 +++- .../templates/settings/integrations.html | 4 +- bookmarks/tests/test_feeds.py | 171 +++++++++++++++++- .../tests/test_settings_integrations_view.py | 8 + bookmarks/urls.py | 9 +- bookmarks/views/settings.py | 8 + 6 files changed, 235 insertions(+), 5 deletions(-) diff --git a/bookmarks/feeds.py b/bookmarks/feeds.py index 7062818..6c8d9f4 100644 --- a/bookmarks/feeds.py +++ b/bookmarks/feeds.py @@ -6,12 +6,12 @@ from django.db.models import QuerySet from django.urls import reverse from bookmarks import queries -from bookmarks.models import Bookmark, BookmarkSearch, FeedToken +from bookmarks.models import Bookmark, BookmarkSearch, FeedToken, UserProfile @dataclass class FeedContext: - feed_token: FeedToken + feed_token: FeedToken | None query_set: QuerySet[Bookmark] @@ -67,3 +67,39 @@ class UnreadBookmarksFeed(BaseBookmarksFeed): def items(self, context: FeedContext): return context.query_set.filter(unread=True) + + +class SharedBookmarksFeed(BaseBookmarksFeed): + title = "Shared bookmarks" + description = "All shared bookmarks" + + def get_object(self, request, feed_key: str): + feed_token = FeedToken.objects.get(key__exact=feed_key) + search = BookmarkSearch(q=request.GET.get("q", "")) + query_set = queries.query_shared_bookmarks( + None, feed_token.user.profile, search, False + ) + return FeedContext(feed_token, query_set) + + def link(self, context: FeedContext): + return reverse("bookmarks:feeds.shared", args=[context.feed_token.key]) + + def items(self, context: FeedContext): + return context.query_set + + +class PublicSharedBookmarksFeed(BaseBookmarksFeed): + title = "Public shared bookmarks" + description = "All public shared bookmarks" + + def get_object(self, request): + search = BookmarkSearch(q=request.GET.get("q", "")) + default_profile = UserProfile() + query_set = queries.query_shared_bookmarks(None, default_profile, search, True) + return FeedContext(None, query_set) + + def link(self, context: FeedContext): + return reverse("bookmarks:feeds.public_shared") + + def items(self, context: FeedContext): + return context.query_set diff --git a/bookmarks/templates/settings/integrations.html b/bookmarks/templates/settings/integrations.html index 8128fc8..c2781de 100644 --- a/bookmarks/templates/settings/integrations.html +++ b/bookmarks/templates/settings/integrations.html @@ -49,9 +49,11 @@

RSS Feeds

The following URLs provide RSS feeds for your bookmarks:

-