Fixes formatting

This commit is contained in:
Ross Chapman 2023-12-06 11:36:15 -08:00
parent 0f6e567b21
commit aac8aa1adf
2 changed files with 26 additions and 11 deletions

View file

@ -14,7 +14,6 @@ from bookwyrm import connectors
from bookwyrm.settings import MEDIA_FULL_URL
@overload
def search(
query: str,
@ -44,7 +43,7 @@ def search(
min_confidence: float = 0,
filters: Optional[list[Any]] = None,
return_first: bool = False,
books: Optional[QuerySet[models.Edition]] = None
books: Optional[QuerySet[models.Edition]] = None,
) -> Union[Optional[models.Edition], QuerySet[models.Edition]]:
"""search your local database"""
filters = filters or []
@ -56,7 +55,9 @@ def search(
# first, try searching unique identifiers
# unique identifiers never have spaces, title/author usually do
if not " " in query:
results = search_identifiers(query, *filters, return_first=return_first, books=books)
results = search_identifiers(
query, *filters, return_first=return_first, books=books
)
# if there were no identifier results...
if not results:
@ -66,6 +67,7 @@ def search(
)
return results
def isbn_search(query):
"""search your local database"""
if not query:
@ -99,10 +101,17 @@ def format_search_result(search_result):
def search_identifiers(
query, *filters, return_first=False, books=None,
query,
*filters,
return_first=False,
books=None,
) -> Union[Optional[models.Edition], QuerySet[models.Edition]]:
"""search Editions by deduplication fields
Best for cases when we can assume someone is searching for an exact match on
commonly unique data identifiers like isbn or specific library ids.
"""
books = books or models.Edition.objects
"""tries remote_id, isbn; defined as dedupe fields on the model"""
if connectors.maybe_isbn(query):
# Oh did you think the 'S' in ISBN stood for 'standard'?
normalized_isbn = query.strip().upper().rjust(10, "0")

View file

@ -1,7 +1,7 @@
""" shelf views """
from collections import namedtuple
from django.db.models import OuterRef, Subquery, F, Max, QuerySet
from django.db.models import OuterRef, Subquery, F, Max
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator
from django.http import HttpResponseBadRequest
@ -17,10 +17,12 @@ from bookwyrm.settings import PAGE_LENGTH
from bookwyrm.views.helpers import is_api_request, get_user_from_username
from bookwyrm.book_search import search
# pylint: disable=no-self-use
class Shelf(View):
"""shelf page"""
# pylint: disable=R0914
def get(self, request, username, shelf_identifier=None):
"""display a shelf"""
user = get_user_from_username(request.user, username)
@ -45,10 +47,14 @@ class Shelf(View):
"Shelf", ("identifier", "name", "user", "books", "privacy")
)
books = models.Edition.viewer_aware_objects(request.user).filter(
# privacy is ensured because the shelves are already filtered above
shelfbook__shelf__in=shelves
).distinct()
books = (
models.Edition.viewer_aware_objects(request.user)
.filter(
# privacy is ensured because the shelves are already filtered above
shelfbook__shelf__in=shelves
)
.distinct()
)
shelf = FakeShelf("all", _("All books"), user, books, "public")
@ -106,7 +112,7 @@ class Shelf(View):
"page_range": paginated.get_elided_page_range(
page.number, on_each_side=2, on_ends=1
),
"shelves_search_query": shelves_search_query
"shelves_search_query": shelves_search_query,
}
return TemplateResponse(request, "shelf/shelf.html", data)