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") editions_of_work = results.values("parent_work__id").values_list("parent_work__id")
# filter out multiple editions of the same work # filter out multiple editions of the same work
results = [] list_results = []
for work_id in set(editions_of_work): for work_id in set(editions_of_work):
editions = results.filter(parent_work=work_id) editions = results.filter(parent_work=work_id)
default = editions.order_by("-edition_rank").first() 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() result = editions.first()
if return_first: if return_first:
return result return result
results.append(result) list_results.append(result)
return results return list_results
@dataclass @dataclass

View file

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

View file

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

View file

@ -17,7 +17,9 @@ class Isbn(View):
book_results = book_search.isbn_search(isbn) book_results = book_search.isbn_search(isbn)
if is_api_request(request): 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( paginated = Paginator(book_results, PAGE_LENGTH).get_page(
request.GET.get("page") request.GET.get("page")