2021-03-08 16:49:10 +00:00
|
|
|
""" isbn search view """
|
2021-03-01 20:09:21 +00:00
|
|
|
from django.http import HttpResponseNotFound
|
|
|
|
from django.http import JsonResponse
|
|
|
|
from django.shortcuts import get_object_or_404, redirect
|
|
|
|
from django.template.response import TemplateResponse
|
|
|
|
from django.utils.decorators import method_decorator
|
|
|
|
from django.views import View
|
|
|
|
from django.views.decorators.http import require_POST
|
|
|
|
|
|
|
|
from bookwyrm import forms, models
|
|
|
|
from bookwyrm.connectors import connector_manager
|
|
|
|
from .helpers import is_api_request
|
|
|
|
|
|
|
|
# pylint: disable= no-self-use
|
|
|
|
class Isbn(View):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""search a book by isbn"""
|
2021-03-08 16:49:10 +00:00
|
|
|
|
2021-03-01 20:09:21 +00:00
|
|
|
def get(self, request, isbn):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""info about a book"""
|
2021-03-01 20:09:21 +00:00
|
|
|
book_results = connector_manager.isbn_local_search(isbn)
|
|
|
|
|
|
|
|
if is_api_request(request):
|
|
|
|
return JsonResponse([r.json() for r in book_results], safe=False)
|
|
|
|
|
|
|
|
data = {
|
2021-03-08 16:49:10 +00:00
|
|
|
"title": "ISBN Search Results",
|
|
|
|
"results": book_results,
|
|
|
|
"query": isbn,
|
2021-03-01 20:09:21 +00:00
|
|
|
}
|
2021-03-08 16:49:10 +00:00
|
|
|
return TemplateResponse(request, "isbn_search_results.html", data)
|