From 979162da10c68cae5ad694d5b3f74d96d84e9acf Mon Sep 17 00:00:00 2001 From: Ross Chapman Date: Tue, 5 Dec 2023 19:33:59 -0800 Subject: [PATCH] Uses filters, fixes for any shelf --- bookwyrm/book_search.py | 1 - .../templates/shelf/search_filter_field.html | 9 +++++++ bookwyrm/templates/shelf/search_filters.html | 5 ++++ .../templates/shelf/search_my_books_form.html | 25 ------------------- bookwyrm/templates/shelf/shelf.html | 5 +++- bookwyrm/views/shelf/shelf.py | 13 +++------- 6 files changed, 21 insertions(+), 37 deletions(-) create mode 100644 bookwyrm/templates/shelf/search_filter_field.html create mode 100644 bookwyrm/templates/shelf/search_filters.html delete mode 100644 bookwyrm/templates/shelf/search_my_books_form.html diff --git a/bookwyrm/book_search.py b/bookwyrm/book_search.py index db7a51426..b3e66cdd6 100644 --- a/bookwyrm/book_search.py +++ b/bookwyrm/book_search.py @@ -60,7 +60,6 @@ def search( # if there were no identifier results... if not results: - print('SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS') # then try searching title/author results = search_title_author( query, min_confidence, *filters, return_first=return_first, books=books diff --git a/bookwyrm/templates/shelf/search_filter_field.html b/bookwyrm/templates/shelf/search_filter_field.html new file mode 100644 index 000000000..591e6aaa9 --- /dev/null +++ b/bookwyrm/templates/shelf/search_filter_field.html @@ -0,0 +1,9 @@ +{% extends 'snippets/filters_panel/filter_field.html' %} +{% load i18n %} + +{% block filter %} +
+ + +
+{% endblock %} diff --git a/bookwyrm/templates/shelf/search_filters.html b/bookwyrm/templates/shelf/search_filters.html new file mode 100644 index 000000000..840eec57e --- /dev/null +++ b/bookwyrm/templates/shelf/search_filters.html @@ -0,0 +1,5 @@ +{% extends 'snippets/filters_panel/filters_panel.html' %} + +{% block filter_fields %} + {% include 'shelf/search_filter_field.html' %} +{% endblock %} diff --git a/bookwyrm/templates/shelf/search_my_books_form.html b/bookwyrm/templates/shelf/search_my_books_form.html deleted file mode 100644 index ca9cd2991..000000000 --- a/bookwyrm/templates/shelf/search_my_books_form.html +++ /dev/null @@ -1,25 +0,0 @@ -{% load i18n %} -{% load utilities %} - - diff --git a/bookwyrm/templates/shelf/shelf.html b/bookwyrm/templates/shelf/shelf.html index b84ae185f..ea5d2343c 100644 --- a/bookwyrm/templates/shelf/shelf.html +++ b/bookwyrm/templates/shelf/shelf.html @@ -121,10 +121,13 @@ {% endblocktrans %} {% endif %} + {% endif %} + {% endwith %} - {% include 'shelf/search_my_books_form.html' with user=user query=query %} + + {% include 'shelf/search_filters.html' with user=user query=query %} {% if is_self and shelf.id %}
diff --git a/bookwyrm/views/shelf/shelf.py b/bookwyrm/views/shelf/shelf.py index 159cc1541..be205597b 100644 --- a/bookwyrm/views/shelf/shelf.py +++ b/bookwyrm/views/shelf/shelf.py @@ -43,8 +43,6 @@ class Shelf(View): shelf = get_object_or_404(user.shelf_set, identifier=shelf_identifier) shelf.raise_visible_to_user(request.user) books = shelf.books - if shelves_search_query: - books = search(shelves_search_query, books=books) else: # this is a constructed "all books" view, with a fake "shelf" obj FakeShelf = namedtuple( @@ -56,11 +54,6 @@ class Shelf(View): shelfbook__shelf__in=shelves ).distinct() - # TODO: [COMMENT] - if shelves_search_query: - books = search(shelves_search_query, books=books) - books = models.Edition.objects.filter(pk__in=books) - shelf = FakeShelf("all", _("All books"), user, books, "public") if is_api_request(request) and shelf_identifier: @@ -83,8 +76,6 @@ class Shelf(View): "start_date" ) - # import pdb; pdb.set_trace() - books = books.annotate(shelved_date=Max("shelfbook__shelved_date")) books = books.annotate( rating=Subquery(reviews.values("rating")[:1]), @@ -99,6 +90,9 @@ class Shelf(View): books = sort_books(books, request.GET.get("sort")) + if shelves_search_query: + books = search(shelves_search_query, books=books) + paginated = Paginator( books, PAGE_LENGTH, @@ -116,7 +110,6 @@ class Shelf(View): "page_range": paginated.get_elided_page_range( page.number, on_each_side=2, on_ends=1 ), - "has_shelves_query": bool(shelves_search_query), "shelves_search_query": shelves_search_query }