From 1c6e5902db227517e452cfd55fe977c5f9c3fb0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20I=C3=9Fbr=C3=BCcker?= Date: Sat, 31 Aug 2024 22:58:41 +0200 Subject: [PATCH] Additional filter parameters for RSS feeds (#811) --- bookmarks/feeds.py | 6 +- .../templates/settings/integrations.html | 10 +++- bookmarks/tests/test_feeds.py | 58 +++++++++++++++++++ 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/bookmarks/feeds.py b/bookmarks/feeds.py index bb3472b..4afc805 100644 --- a/bookmarks/feeds.py +++ b/bookmarks/feeds.py @@ -30,7 +30,11 @@ def sanitize(text: str): class BaseBookmarksFeed(Feed): def get_object(self, request, feed_key: str | None): feed_token = FeedToken.objects.get(key__exact=feed_key) if feed_key else None - search = BookmarkSearch(q=request.GET.get("q", "")) + search = BookmarkSearch( + q=request.GET.get("q", ""), + unread=request.GET.get("unread", ""), + shared=request.GET.get("shared", ""), + ) query_set = self.get_query_set(feed_token, search) return FeedContext(request, feed_token, query_set) diff --git a/bookmarks/templates/settings/integrations.html b/bookmarks/templates/settings/integrations.html index 02d3d40..3ac1982 100644 --- a/bookmarks/templates/settings/integrations.html +++ b/bookmarks/templates/settings/integrations.html @@ -64,11 +64,17 @@ All URLs support the following URL parameters:

diff --git a/bookmarks/tests/test_feeds.py b/bookmarks/tests/test_feeds.py index 1dba4d6..7b512c4 100644 --- a/bookmarks/tests/test_feeds.py +++ b/bookmarks/tests/test_feeds.py @@ -253,6 +253,64 @@ class FeedsTestCase(TestCase, BookmarkFactoryMixin): self.assertContains(response, "", count=1) self.assertContains(response, f"{bookmark2.url}", count=1) + def test_unread_parameter(self): + self.setup_bookmark(unread=True), + self.setup_bookmark(unread=True), + self.setup_bookmark(unread=False), + self.setup_bookmark(unread=False), + self.setup_bookmark(unread=False), + self.setup_bookmark(unread=False), + + # without unread parameter + response = self.client.get( + reverse("bookmarks:feeds.all", args=[self.token.key]) + ) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "", count=6) + + # with unread=yes + response = self.client.get( + reverse("bookmarks:feeds.all", args=[self.token.key]) + "?unread=yes" + ) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "", count=2) + + # with unread=no + response = self.client.get( + reverse("bookmarks:feeds.all", args=[self.token.key]) + "?unread=no" + ) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "", count=4) + + def test_shared_parameter(self): + self.setup_bookmark(shared=True) + self.setup_bookmark(shared=True) + self.setup_bookmark(shared=False) + self.setup_bookmark(shared=False) + self.setup_bookmark(shared=False) + self.setup_bookmark(shared=False) + + # without shared parameter + response = self.client.get( + reverse("bookmarks:feeds.all", args=[self.token.key]) + ) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "", count=6) + + # with shared=yes + response = self.client.get( + reverse("bookmarks:feeds.all", args=[self.token.key]) + "?shared=yes" + ) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "", count=2) + + # with shared=no + response = self.client.get( + reverse("bookmarks:feeds.all", args=[self.token.key]) + "?shared=no" + ) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "", count=4) + def test_with_tags(self): bookmarks = [ self.setup_bookmark(description="test description"),