Fixes circular import

This commit is contained in:
Mouse Reeve 2021-09-16 11:30:04 -07:00
parent fbe05623ff
commit 18591c7b56
5 changed files with 32 additions and 30 deletions

View file

@ -1,4 +1,5 @@
""" using a bookwyrm instance as a source of book data """
from dataclasses import asdict, dataclass
from functools import reduce
import operator
@ -6,7 +7,6 @@ from django.contrib.postgres.search import SearchRank, SearchQuery
from django.db.models import OuterRef, Subquery, F, Q
from bookwyrm import models
from bookwyrm.connectors.abstract_connector import SearchResult
from bookwyrm.settings import MEDIA_FULL_URL
@ -128,3 +128,28 @@ def search_title_author(query, min_confidence, *filters, return_first=False):
return result
results.append(result)
return results
@dataclass
class SearchResult:
"""standardized search result object"""
title: str
key: str
connector: object
view_link: str = None
author: str = None
year: str = None
cover: str = None
confidence: int = 1
def __repr__(self):
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

View file

@ -1,6 +1,5 @@
""" functionality outline for a book data connector """
from abc import ABC, abstractmethod
from dataclasses import asdict, dataclass
import logging
from django.db import transaction
@ -268,31 +267,6 @@ def get_image(url, timeout=10):
return resp
@dataclass
class SearchResult:
"""standardized search result object"""
title: str
key: str
connector: object
view_link: str = None
author: str = None
year: str = None
cover: str = None
confidence: int = 1
def __repr__(self):
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

@ -1,6 +1,7 @@
""" using another bookwyrm instance as a source of book data """
from bookwyrm import activitypub, models
from .abstract_connector import AbstractMinimalConnector, SearchResult
from bookwyrm.book_search import SearchResult
from .abstract_connector import AbstractMinimalConnector
class Connector(AbstractMinimalConnector):

View file

@ -2,7 +2,8 @@
import re
from bookwyrm import models
from .abstract_connector import AbstractConnector, SearchResult, Mapping
from bookwyrm.book_search import SearchResult
from .abstract_connector import AbstractConnector, Mapping
from .abstract_connector import get_data
from .connector_manager import ConnectorException

View file

@ -2,7 +2,8 @@
import re
from bookwyrm import models
from .abstract_connector import AbstractConnector, SearchResult, Mapping
from bookwyrm.book_search import SearchResult
from .abstract_connector import AbstractConnector, Mapping
from .abstract_connector import get_data
from .connector_manager import ConnectorException
from .openlibrary_languages import languages