mirror of
https://github.com/sissbruecker/linkding
synced 2024-11-10 06:04:15 +00:00
0975914a86
* Rename BookmarkFilters to BookmarkSearch * Refactor queries to accept BookmarkSearch * Sort query by data added and title * Ensure pagination respects search parameters * Ensure tag cloud respects search parameters * Ensure user select respects search parameters * Ensure return url respects search options * Fix passing search options to user select * Fix BookmarkSearch initialization * Extract common search form logic * Ensure partial update respects search options * Add sort UI * Use custom ICU collation when sorting with SQLite * Support sort in API
56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
from dataclasses import dataclass
|
|
|
|
from django.contrib.syndication.views import Feed
|
|
from django.db.models import QuerySet
|
|
from django.urls import reverse
|
|
|
|
from bookmarks.models import Bookmark, BookmarkSearch, FeedToken
|
|
from bookmarks import queries
|
|
|
|
|
|
@dataclass
|
|
class FeedContext:
|
|
feed_token: FeedToken
|
|
query_set: QuerySet[Bookmark]
|
|
|
|
|
|
class BaseBookmarksFeed(Feed):
|
|
def get_object(self, request, feed_key: str):
|
|
feed_token = FeedToken.objects.get(key__exact=feed_key)
|
|
search = BookmarkSearch(query=request.GET.get('q', ''))
|
|
query_set = queries.query_bookmarks(feed_token.user, feed_token.user.profile, search)
|
|
return FeedContext(feed_token, query_set)
|
|
|
|
def item_title(self, item: Bookmark):
|
|
return item.resolved_title
|
|
|
|
def item_description(self, item: Bookmark):
|
|
return item.resolved_description
|
|
|
|
def item_link(self, item: Bookmark):
|
|
return item.url
|
|
|
|
def item_pubdate(self, item: Bookmark):
|
|
return item.date_added
|
|
|
|
|
|
class AllBookmarksFeed(BaseBookmarksFeed):
|
|
title = 'All bookmarks'
|
|
description = 'All bookmarks'
|
|
|
|
def link(self, context: FeedContext):
|
|
return reverse('bookmarks:feeds.all', args=[context.feed_token.key])
|
|
|
|
def items(self, context: FeedContext):
|
|
return context.query_set
|
|
|
|
|
|
class UnreadBookmarksFeed(BaseBookmarksFeed):
|
|
title = 'Unread bookmarks'
|
|
description = 'All unread bookmarks'
|
|
|
|
def link(self, context: FeedContext):
|
|
return reverse('bookmarks:feeds.unread', args=[context.feed_token.key])
|
|
|
|
def items(self, context: FeedContext):
|
|
return context.query_set.filter(unread=True)
|