mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-28 02:50:38 +00:00
Fixes API search causing 500 error
This commit is contained in:
parent
8ffb22291a
commit
e5a914c3c2
2 changed files with 8 additions and 2 deletions
|
@ -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 '''
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue