diff --git a/bookwyrm/book_search.py b/bookwyrm/book_search.py index 6ab33fd5a..db7a51426 100644 --- a/bookwyrm/book_search.py +++ b/bookwyrm/book_search.py @@ -14,6 +14,7 @@ from bookwyrm import connectors from bookwyrm.settings import MEDIA_FULL_URL + @overload def search( query: str, @@ -43,7 +44,7 @@ def search( min_confidence: float = 0, filters: Optional[list[Any]] = None, return_first: bool = False, - books = None + books: Optional[QuerySet[models.Edition]] = None ) -> Union[Optional[models.Edition], QuerySet[models.Edition]]: """search your local database""" filters = filters or [] @@ -59,6 +60,7 @@ 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 @@ -100,7 +102,7 @@ def format_search_result(search_result): def search_identifiers( query, *filters, return_first=False, books=None, ) -> Union[Optional[models.Edition], QuerySet[models.Edition]]: - books = books or models.Edition + 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'? diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 49e4e2116..c5f5f52f4 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -194,7 +194,7 @@ LOGGING = { # Add a bookwyrm-specific logger "bookwyrm": { "handlers": ["console"], - "level": LOG_LEVEL, + "level": DEBUG, }, }, } diff --git a/bookwyrm/views/shelf/shelf.py b/bookwyrm/views/shelf/shelf.py index 600dfb731..159cc1541 100644 --- a/bookwyrm/views/shelf/shelf.py +++ b/bookwyrm/views/shelf/shelf.py @@ -43,21 +43,23 @@ 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( "Shelf", ("identifier", "name", "user", "books", "privacy") ) - if shelves_search_query: - logger.debug("AAAAAAAAAAAA") - all_books = models.Edition.viewer_aware_objects(request.user).filter( + + 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 + + # 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") @@ -81,6 +83,8 @@ 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]),