mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-29 21:11:16 +00:00
Set connectors on books
This commit is contained in:
parent
1a33290267
commit
0c9aad730d
4 changed files with 6 additions and 4 deletions
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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'):
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue