Uses filters, fixes for any shelf

This commit is contained in:
Ross Chapman 2023-12-05 19:33:59 -08:00
parent b27ed847d5
commit 979162da10
6 changed files with 21 additions and 37 deletions

View file

@ -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

View file

@ -0,0 +1,9 @@
{% extends 'snippets/filters_panel/filter_field.html' %}
{% load i18n %}
{% block filter %}
<div class="control">
<label class="label" for="search_query">{% trans 'Search by keyword' %}</label>
<input aria-label="Search by keyword" id="my-books-search" class="input" type="text" name="shelves_q" placeholder="Enter text here" value="{{ shelves_search_query }}" spellcheck="false" />
</div>
{% endblock %}

View file

@ -0,0 +1,5 @@
{% extends 'snippets/filters_panel/filters_panel.html' %}
{% block filter_fields %}
{% include 'shelf/search_filter_field.html' %}
{% endblock %}

View file

@ -1,25 +0,0 @@
{% load i18n %}
{% load utilities %}
<form class="navbar-item column is-align-items-start pt-5" action="{% url 'user-shelves' user|username %}">
<div class="field has-addons">
<div class="control">
{% trans "Search for a book" as my_shelves_search_placeholder %}
<input aria-label="{{ my_shelves_search_placeholder }}" id="my-books-search" class="input" type="text" name="shelves_q" placeholder="{{ my_shelves_search_placeholder }}" value="{{ my_shelves_query }}" spellcheck="false">
</div>
<div class="control">
<button class="button" type="submit">
<span class="icon icon-search" title="{% trans 'Search' %}">
<span class="is-sr-only">{% trans "Search" %}</span>
</span>
</button>
</div>
<div class="control">
<button class="button" type="button" data-modal-open="barcode-scanner-modal">
<span class="icon icon-barcode" title="{% trans 'Scan Barcode' %}" id="tour-barcode">
<span class="is-sr-only">{% trans "Scan Barcode" %}</span>
</span>
</button>
</div>
</div>
</form>

View file

@ -121,10 +121,13 @@
{% endblocktrans %}
{% endif %}
</span>
{% endif %}
{% endwith %}
{% include 'shelf/search_my_books_form.html' with user=user query=query %}
</h2>
{% include 'shelf/search_filters.html' with user=user query=query %}
</div>
{% if is_self and shelf.id %}
<div class="column is-narrow">

View file

@ -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
}