mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +00:00
Uses filters, fixes for any shelf
This commit is contained in:
parent
b27ed847d5
commit
979162da10
6 changed files with 21 additions and 37 deletions
|
@ -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
|
||||
|
|
9
bookwyrm/templates/shelf/search_filter_field.html
Normal file
9
bookwyrm/templates/shelf/search_filter_field.html
Normal 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 %}
|
5
bookwyrm/templates/shelf/search_filters.html
Normal file
5
bookwyrm/templates/shelf/search_filters.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
{% extends 'snippets/filters_panel/filters_panel.html' %}
|
||||
|
||||
{% block filter_fields %}
|
||||
{% include 'shelf/search_filter_field.html' %}
|
||||
{% endblock %}
|
|
@ -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>
|
|
@ -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">
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue