Load covers in fedireads connector

This commit is contained in:
Mouse Reeve
2020-05-09 12:53:55 -07:00
parent 5924e8ed63
commit 8c3e208282
3 changed files with 41 additions and 62 deletions

View File

@ -94,6 +94,27 @@ class AbstractConnector(ABC):
return book
def update_book(self, book, data=None):
''' load new data '''
if not book.sync and not book.sync_cover:
return
if not data:
key = getattr(book, self.key_name)
data = self.load_book_data(key)
if book.sync_cover:
book.cover.save(*self.get_cover_from_data(data), save=True)
if book.sync:
book = self.update_book_from_data(book, data)
return book
def load_book_data(self, remote_id):
''' default method for loading book data '''
return get_data(remote_id)
@abstractmethod
def get_authors_from_data(self, data):
''' load author data '''
@ -131,12 +152,6 @@ class AbstractConnector(ABC):
# return book model obj
@abstractmethod
def update_book(self, book_obj, data=None):
''' sync a book with the canonical remote copy '''
# return book model obj
def update_from_mappings(obj, data, mappings):
''' assign data to model with mappings '''
noop = lambda x: x