Fixes formatting isbn endpoint results

This commit is contained in:
Mouse Reeve 2021-09-16 12:52:10 -07:00
parent 22af7ece71
commit 8c4cafed79
4 changed files with 11 additions and 11 deletions

View file

@ -114,7 +114,7 @@ def search_title_author(query, min_confidence, *filters, return_first=False):
editions_of_work = results.values("parent_work__id").values_list("parent_work__id")
# filter out multiple editions of the same work
results = []
list_results = []
for work_id in set(editions_of_work):
editions = results.filter(parent_work=work_id)
default = editions.order_by("-edition_rank").first()
@ -126,8 +126,8 @@ def search_title_author(query, min_confidence, *filters, return_first=False):
result = editions.first()
if return_first:
return result
results.append(result)
return results
list_results.append(result)
return list_results
@dataclass

View file

@ -119,12 +119,10 @@ class AbstractConnector(TestCase):
@responses.activate
def test_get_or_create_author(self):
"""load an author"""
self.connector.author_mappings = ( # pylint: disable=attribute-defined-outside-init
[ # pylint: disable=attribute-defined-outside-init
self.connector.author_mappings = [ # pylint: disable=attribute-defined-outside-init # pylint: disable=attribute-defined-outside-init
Mapping("id"),
Mapping("name"),
]
)
responses.add(
responses.GET,

View file

@ -35,7 +35,7 @@ class IsbnViews(TestCase):
parent_work=self.work,
)
models.Connector.objects.create(
identifier="self", connector_file="self_connector", local=True
identifier="self", connector_file="self_connector"
)
models.SiteSettings.objects.create()

View file

@ -17,7 +17,9 @@ class Isbn(View):
book_results = book_search.isbn_search(isbn)
if is_api_request(request):
return JsonResponse([r.json() for r in book_results], safe=False)
return JsonResponse(
[book_search.format_search_result(r) for r in book_results], safe=False
)
paginated = Paginator(book_results, PAGE_LENGTH).get_page(
request.GET.get("page")