From 9fad5b5623c1de48316bc7932fb91c5eed59f5c2 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 5 Aug 2022 11:43:11 -0700 Subject: [PATCH] Fixes isbn view --- bookwyrm/tests/views/test_isbn.py | 5 +++-- bookwyrm/views/isbn.py | 13 ++++++++----- bookwyrm/views/search.py | 4 +++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/bookwyrm/tests/views/test_isbn.py b/bookwyrm/tests/views/test_isbn.py index 7c18b4abd..e09379418 100644 --- a/bookwyrm/tests/views/test_isbn.py +++ b/bookwyrm/tests/views/test_isbn.py @@ -7,13 +7,14 @@ from django.test import TestCase from django.test.client import RequestFactory from bookwyrm import models, views +from bookwyrm.tests.validate_html import validate_html from bookwyrm.settings import DOMAIN class IsbnViews(TestCase): """tag views""" - def setUp(self): + def setUp(self): # pylint: disable=invalid-name """we need basic test data and mocks""" self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( @@ -58,4 +59,4 @@ class IsbnViews(TestCase): is_api.return_value = False response = view(request, isbn="1234567890123") self.assertEqual(response.status_code, 200) - response.render() + validate_html(response.render()) diff --git a/bookwyrm/views/isbn.py b/bookwyrm/views/isbn.py index e5343488d..728936e1f 100644 --- a/bookwyrm/views/isbn.py +++ b/bookwyrm/views/isbn.py @@ -18,14 +18,17 @@ class Isbn(View): if is_api_request(request): return JsonResponse( - [book_search.format_search_result(r) for r in book_results], safe=False + [book_search.format_search_result(r) for r in book_results[:10]], + safe=False, ) - paginated = Paginator(book_results, PAGE_LENGTH).get_page( - request.GET.get("page") - ) + paginated = Paginator(book_results, PAGE_LENGTH) + page = paginated.get_page(request.GET.get("page")) data = { - "results": [{"results": paginated}], + "results": page, + "page_range": paginated.get_elided_page_range( + page.number, on_each_side=2, on_ends=1 + ), "query": isbn, "type": "book", } diff --git a/bookwyrm/views/search.py b/bookwyrm/views/search.py index 997a5f841..db33fd330 100644 --- a/bookwyrm/views/search.py +++ b/bookwyrm/views/search.py @@ -52,7 +52,9 @@ def api_book_search(request): 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) - return JsonResponse([format_search_result(r) for r in book_results], safe=False) + return JsonResponse( + [format_search_result(r) for r in book_results[:10]], safe=False + ) def book_search(request):