mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-25 01:20:35 +00:00
Fixes isbn view
This commit is contained in:
parent
b4cfda0587
commit
9fad5b5623
3 changed files with 14 additions and 8 deletions
|
@ -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())
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue