mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +00:00
Fixes result set passed to template
This commit is contained in:
parent
d93da4e86d
commit
b27ed847d5
3 changed files with 16 additions and 10 deletions
|
@ -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'?
|
||||
|
|
|
@ -194,7 +194,7 @@ LOGGING = {
|
|||
# Add a bookwyrm-specific logger
|
||||
"bookwyrm": {
|
||||
"handlers": ["console"],
|
||||
"level": LOG_LEVEL,
|
||||
"level": DEBUG,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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]),
|
||||
|
|
Loading…
Reference in a new issue