Use search results template for isbn view

This commit is contained in:
Mouse Reeve 2021-08-21 10:48:26 -07:00
parent 053579c2a4
commit 85a4c331eb
2 changed files with 8 additions and 35 deletions

View file

@ -1,33 +0,0 @@
{% extends 'layout.html' %}
{% load i18n %}
{% block title %}{% trans "Search Results" %}{% endblock %}
{% block content %}
{% with book_results|first as local_results %}
<div class="block">
<h1 class="title">{% blocktrans %}Search Results for "{{ query }}"{% endblocktrans %}</h1>
</div>
<div class="block columns">
<div class="column">
<h2 class="title">{% trans "Matching Books" %}</h2>
<section class="block">
{% if not results %}
<p>{% blocktrans %}No books found for "{{ query }}"{% endblocktrans %}</p>
{% else %}
<ul>
{% for result in results %}
<li class="pd-4">
<a href="{{ result.key }}">{% include 'snippets/search_result_text.html' with result=result link=True %}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</section>
<div class="column">
</div>
</div>
{% endwith %}
{% endblock %}

View file

@ -1,9 +1,11 @@
""" isbn search view """
from django.core.paginator import Paginator
from django.http import JsonResponse
from django.template.response import TemplateResponse
from django.views import View
from bookwyrm.connectors import connector_manager
from bookwyrm.settings import PAGE_LENGTH
from .helpers import is_api_request
# pylint: disable= no-self-use
@ -17,8 +19,12 @@ class Isbn(View):
if is_api_request(request):
return JsonResponse([r.json() for r in book_results], safe=False)
paginated = Paginator(book_results, PAGE_LENGTH).get_page(
request.GET.get("page")
)
data = {
"results": book_results,
"results": [{"results": paginated}],
"query": isbn,
"type": "book",
}
return TemplateResponse(request, "isbn_search_results.html", data)
return TemplateResponse(request, "search/book.html", data)