mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-30 05:21: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
|
from bookwyrm.settings import MEDIA_FULL_URL
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def search(
|
def search(
|
||||||
query: str,
|
query: str,
|
||||||
|
@ -43,7 +44,7 @@ def search(
|
||||||
min_confidence: float = 0,
|
min_confidence: float = 0,
|
||||||
filters: Optional[list[Any]] = None,
|
filters: Optional[list[Any]] = None,
|
||||||
return_first: bool = False,
|
return_first: bool = False,
|
||||||
books = None
|
books: Optional[QuerySet[models.Edition]] = None
|
||||||
) -> Union[Optional[models.Edition], QuerySet[models.Edition]]:
|
) -> Union[Optional[models.Edition], QuerySet[models.Edition]]:
|
||||||
"""search your local database"""
|
"""search your local database"""
|
||||||
filters = filters or []
|
filters = filters or []
|
||||||
|
@ -59,6 +60,7 @@ def search(
|
||||||
|
|
||||||
# if there were no identifier results...
|
# if there were no identifier results...
|
||||||
if not results:
|
if not results:
|
||||||
|
print('SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS')
|
||||||
# then try searching title/author
|
# then try searching title/author
|
||||||
results = search_title_author(
|
results = search_title_author(
|
||||||
query, min_confidence, *filters, return_first=return_first, books=books
|
query, min_confidence, *filters, return_first=return_first, books=books
|
||||||
|
@ -100,7 +102,7 @@ def format_search_result(search_result):
|
||||||
def search_identifiers(
|
def search_identifiers(
|
||||||
query, *filters, return_first=False, books=None,
|
query, *filters, return_first=False, books=None,
|
||||||
) -> Union[Optional[models.Edition], QuerySet[models.Edition]]:
|
) -> 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"""
|
"""tries remote_id, isbn; defined as dedupe fields on the model"""
|
||||||
if connectors.maybe_isbn(query):
|
if connectors.maybe_isbn(query):
|
||||||
# Oh did you think the 'S' in ISBN stood for 'standard'?
|
# Oh did you think the 'S' in ISBN stood for 'standard'?
|
||||||
|
|
|
@ -194,7 +194,7 @@ LOGGING = {
|
||||||
# Add a bookwyrm-specific logger
|
# Add a bookwyrm-specific logger
|
||||||
"bookwyrm": {
|
"bookwyrm": {
|
||||||
"handlers": ["console"],
|
"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 = get_object_or_404(user.shelf_set, identifier=shelf_identifier)
|
||||||
shelf.raise_visible_to_user(request.user)
|
shelf.raise_visible_to_user(request.user)
|
||||||
books = shelf.books
|
books = shelf.books
|
||||||
|
if shelves_search_query:
|
||||||
|
books = search(shelves_search_query, books=books)
|
||||||
else:
|
else:
|
||||||
# this is a constructed "all books" view, with a fake "shelf" obj
|
# this is a constructed "all books" view, with a fake "shelf" obj
|
||||||
FakeShelf = namedtuple(
|
FakeShelf = namedtuple(
|
||||||
"Shelf", ("identifier", "name", "user", "books", "privacy")
|
"Shelf", ("identifier", "name", "user", "books", "privacy")
|
||||||
)
|
)
|
||||||
if shelves_search_query:
|
|
||||||
logger.debug("AAAAAAAAAAAA")
|
books = models.Edition.viewer_aware_objects(request.user).filter(
|
||||||
all_books = models.Edition.viewer_aware_objects(request.user).filter(
|
|
||||||
# privacy is ensured because the shelves are already filtered above
|
# privacy is ensured because the shelves are already filtered above
|
||||||
shelfbook__shelf__in=shelves
|
shelfbook__shelf__in=shelves
|
||||||
).distinct()
|
).distinct()
|
||||||
books = search(shelves_search_query, books=all_books)
|
|
||||||
else:
|
# TODO: [COMMENT]
|
||||||
logger.debug("BBBBBBBBB")
|
if shelves_search_query:
|
||||||
books = shelf.books
|
books = search(shelves_search_query, books=books)
|
||||||
|
books = models.Edition.objects.filter(pk__in=books)
|
||||||
|
|
||||||
shelf = FakeShelf("all", _("All books"), user, books, "public")
|
shelf = FakeShelf("all", _("All books"), user, books, "public")
|
||||||
|
|
||||||
|
@ -81,6 +83,8 @@ class Shelf(View):
|
||||||
"start_date"
|
"start_date"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# import pdb; pdb.set_trace()
|
||||||
|
|
||||||
books = books.annotate(shelved_date=Max("shelfbook__shelved_date"))
|
books = books.annotate(shelved_date=Max("shelfbook__shelved_date"))
|
||||||
books = books.annotate(
|
books = books.annotate(
|
||||||
rating=Subquery(reviews.values("rating")[:1]),
|
rating=Subquery(reviews.values("rating")[:1]),
|
||||||
|
|
Loading…
Reference in a new issue