Fixes API search causing 500 error

This commit is contained in:
Mouse Reeve 2020-12-30 11:37:26 -08:00
parent 8ffb22291a
commit e5a914c3c2
2 changed files with 8 additions and 2 deletions

View file

@ -1,6 +1,6 @@
''' functionality outline for a book data connector '''
from abc import ABC, abstractmethod
from dataclasses import dataclass
from dataclasses import asdict, dataclass
import logging
from urllib3.exceptions import RequestError
@ -241,6 +241,12 @@ class SearchResult:
return "<SearchResult key={!r} title={!r} author={!r}>".format(
self.key, self.title, self.author)
def json(self):
''' serialize a connector for json response '''
serialized = asdict(self)
del serialized['connector']
return serialized
class Mapping:
''' associate a local database field with a field in an external dataset '''

View file

@ -210,7 +210,7 @@ def search(request):
if is_api_request(request):
# only return local book results via json so we don't cause a cascade
book_results = books_manager.local_search(query)
return JsonResponse([r.__dict__ for r in book_results], safe=False)
return JsonResponse([r.json() for r in book_results], safe=False)
# use webfinger for mastodon style account@domain.com username
if re.match(regex.full_username, query):