1
0
Fork 0

Checkpoint

This commit is contained in:
Ross Chapman 2023-11-27 15:03:59 -08:00
parent 90cc28986e
commit d93da4e86d
8 changed files with 66 additions and 21 deletions

View file

@ -51,7 +51,7 @@ class Search(View):
def api_book_search(request):
"""Return books via API response"""
query = request.GET.get("q")
query = isbn_check(query)
query = isbn_check_and_format(query)
min_confidence = request.GET.get("min_confidence", 0)
# only return local book results via json so we don't cascade
book_results = search(query, min_confidence=min_confidence)
@ -64,7 +64,7 @@ def book_search(request):
"""the real business is elsewhere"""
query = request.GET.get("q")
# check if query is isbn
query = isbn_check(query)
query = isbn_check_and_format(query)
min_confidence = request.GET.get("min_confidence", 0)
search_remote = request.GET.get("remote", False) and request.user.is_authenticated
@ -159,7 +159,7 @@ def list_search(request):
return TemplateResponse(request, "search/list.html", data)
def isbn_check(query):
def isbn_check_and_format(query):
"""isbn10 or isbn13 check, if so remove separators"""
if query:
su_num = re.sub(r"(?<=\d)\D(?=\d|[xX])", "", query)

View file

@ -1,7 +1,7 @@
""" shelf views """
from collections import namedtuple
from django.db.models import OuterRef, Subquery, F, Max
from django.db.models import OuterRef, Subquery, F, Max, QuerySet
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator
from django.http import HttpResponseBadRequest
@ -15,6 +15,10 @@ from bookwyrm import forms, models
from bookwyrm.activitypub import ActivitypubResponse
from bookwyrm.settings import PAGE_LENGTH
from bookwyrm.views.helpers import is_api_request, get_user_from_username
from bookwyrm.book_search import search
import logging
logger = logging.getLogger(__name__)
# pylint: disable=no-self-use
@ -32,6 +36,8 @@ class Shelf(View):
else:
shelves = models.Shelf.privacy_filter(request.user).filter(user=user).all()
shelves_search_query = request.GET.get("shelves_q")
# get the shelf and make sure the logged in user should be able to see it
if shelf_identifier:
shelf = get_object_or_404(user.shelf_set, identifier=shelf_identifier)
@ -42,14 +48,17 @@ class Shelf(View):
FakeShelf = namedtuple(
"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()
)
if shelves_search_query:
logger.debug("AAAAAAAAAAAA")
all_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 = search(shelves_search_query, books=all_books)
else:
logger.debug("BBBBBBBBB")
books = shelf.books
shelf = FakeShelf("all", _("All books"), user, books, "public")
if is_api_request(request) and shelf_identifier:
@ -103,6 +112,8 @@ 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
}
return TemplateResponse(request, "shelf/shelf.html", data)