Set connectors on books

This commit is contained in:
Mouse Reeve 2020-03-28 16:01:02 -07:00
parent 1a33290267
commit 0c9aad730d
4 changed files with 6 additions and 4 deletions

View file

@ -19,7 +19,7 @@ def get_or_create_book(key):
def search(query): def search(query):
''' ya ''' ''' try an external datasource for books '''
connector = get_connector() connector = get_connector()
return connector.search(query) return connector.search(query)

View file

@ -10,7 +10,7 @@ class AbstractConnector(ABC):
def __init__(self, identifier): def __init__(self, identifier):
# load connector settings # load connector settings
info = models.Connector.objects.get(identifier=identifier) info = models.Connector.objects.get(identifier=identifier)
self.model = info self.connector = info
self.url = info.base_url self.url = info.base_url
self.covers_url = info.covers_url self.covers_url = info.covers_url
@ -21,8 +21,8 @@ class AbstractConnector(ABC):
def is_available(self): def is_available(self):
''' check if you're allowed to use this connector ''' ''' check if you're allowed to use this connector '''
if self.model.max_query_count is not None: if self.connector.max_query_count is not None:
if self.model.query_count >= self.model.max_query_count: if self.connector.query_count >= self.connector.max_query_count:
return False return False
return True return True

View file

@ -61,6 +61,7 @@ class Connector(AbstractConnector):
book = update_from_mappings(book, data, mappings) book = update_from_mappings(book, data, mappings)
book.source_url = response.url book.source_url = response.url
book.connector = self.connector
book.save() book.save()
if data.get('parent_work'): if data.get('parent_work'):

View file

@ -82,6 +82,7 @@ class Connector(AbstractConnector):
book.goodreads_key = data['identifiers']['goodreads'] book.goodreads_key = data['identifiers']['goodreads']
book.source_url = response.url book.source_url = response.url
book.connector = self.connector
book.save() book.save()
# this book sure as heck better be an edition # this book sure as heck better be an edition