mirror of
https://github.com/sissbruecker/linkding
synced 2024-11-10 06:04:15 +00:00
Additional filter parameters for RSS feeds (#811)
This commit is contained in:
parent
20fe88dd57
commit
1c6e5902db
3 changed files with 71 additions and 3 deletions
|
@ -30,7 +30,11 @@ def sanitize(text: str):
|
||||||
class BaseBookmarksFeed(Feed):
|
class BaseBookmarksFeed(Feed):
|
||||||
def get_object(self, request, feed_key: str | None):
|
def get_object(self, request, feed_key: str | None):
|
||||||
feed_token = FeedToken.objects.get(key__exact=feed_key) if feed_key else 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)
|
query_set = self.get_query_set(feed_token, search)
|
||||||
return FeedContext(request, feed_token, query_set)
|
return FeedContext(request, feed_token, query_set)
|
||||||
|
|
||||||
|
|
|
@ -64,11 +64,17 @@
|
||||||
All URLs support the following URL parameters:
|
All URLs support the following URL parameters:
|
||||||
</p>
|
</p>
|
||||||
<ul style="list-style-position: outside;">
|
<ul style="list-style-position: outside;">
|
||||||
|
<li>A <code>limit</code> parameter for specifying the maximum number of bookmarks to include in the feed. By
|
||||||
|
default, only the latest 100 matching bookmarks are included.
|
||||||
|
</li>
|
||||||
<li>A <code>q</code> URL parameter for specifying a search query. You can get an example by doing a search in
|
<li>A <code>q</code> URL parameter for specifying a search query. You can get an example by doing a search in
|
||||||
the bookmarks view and then copying the parameter from the URL.
|
the bookmarks view and then copying the parameter from the URL.
|
||||||
</li>
|
</li>
|
||||||
<li>A <code>limit</code> parameter for specifying the maximum number of bookmarks to include in the feed. By
|
<li>An <code>unread</code> parameter for filtering for unread or read bookmarks. Use <code>yes</code> for unread
|
||||||
default, only the latest 100 matching bookmarks are included.
|
bookmarks and <code>no</code> for read bookmarks.
|
||||||
|
</li>
|
||||||
|
<li>A <code>shared</code> parameter for filtering for shared or unshared bookmarks. Use <code>yes</code> for
|
||||||
|
shared bookmarks and <code>no</code> for unshared bookmarks.
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -253,6 +253,64 @@ class FeedsTestCase(TestCase, BookmarkFactoryMixin):
|
||||||
self.assertContains(response, "<item>", count=1)
|
self.assertContains(response, "<item>", count=1)
|
||||||
self.assertContains(response, f"<guid>{bookmark2.url}</guid>", count=1)
|
self.assertContains(response, f"<guid>{bookmark2.url}</guid>", 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, "<item>", 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, "<item>", 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, "<item>", 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, "<item>", 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, "<item>", 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, "<item>", count=4)
|
||||||
|
|
||||||
def test_with_tags(self):
|
def test_with_tags(self):
|
||||||
bookmarks = [
|
bookmarks = [
|
||||||
self.setup_bookmark(description="test description"),
|
self.setup_bookmark(description="test description"),
|
||||||
|
|
Loading…
Reference in a new issue