From 0393d8123073a3c130e0cc61a373152ebb4cd04f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Oct 2020 17:18:25 -0700 Subject: [PATCH] Fixes loading covers and authors --- bookwyrm/activitypub/base_activity.py | 1 - bookwyrm/connectors/abstract_connector.py | 2 -- bookwyrm/connectors/bookwyrm_connector.py | 8 ++++++-- bookwyrm/models/book.py | 9 +++++++++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index 1cffd0edc..fc5b11288 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -15,7 +15,6 @@ class ActivityEncoder(JSONEncoder): @dataclass class Image: ''' image block ''' - mediaType: str url: str type: str = 'Image' diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index c6e2f19ee..9f9aed43a 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -146,13 +146,11 @@ class AbstractConnector(ABC): def create_book(self, remote_id, data, model): ''' create a work or edition from data ''' - print(remote_id) book = model.objects.create( remote_id=remote_id, title=data['title'], connector=self.connector, ) - print(book.remote_id) return self.update_book_from_data(book, data) diff --git a/bookwyrm/connectors/bookwyrm_connector.py b/bookwyrm/connectors/bookwyrm_connector.py index 072910b63..c7a0f2ece 100644 --- a/bookwyrm/connectors/bookwyrm_connector.py +++ b/bookwyrm/connectors/bookwyrm_connector.py @@ -41,9 +41,13 @@ class Connector(AbstractConnector): ] self.author_mappings = [ - Mapping('born', remote_field='birth_date', formatter=get_date), - Mapping('died', remote_field='death_date', formatter=get_date), + Mapping('name'), Mapping('bio'), + Mapping('openlibrary_key'), + Mapping('wikipedia_link'), + Mapping('aliases'), + Mapping('born', formatter=get_date), + Mapping('died', formatter=get_date), ] diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index 03b2c1f8b..0920a9313 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -58,6 +58,14 @@ class Book(ActivitypubMixin, BookWyrmModel): ''' the activitypub serialization should be a list of author ids ''' return [a.remote_id for a in self.authors.all()] + @property + def ap_cover(self): + ''' an image attachment ''' + return [activitypub.Image( + url='https://%s%s' % (DOMAIN, self.cover.url), + )] + + activity_mappings = [ ActivityMapping('id', 'remote_id'), @@ -90,6 +98,7 @@ class Book(ActivitypubMixin, BookWyrmModel): ActivityMapping('lccn', 'lccn'), ActivityMapping('editions', 'editions_path'), + ActivityMapping('attachment', 'ap_cover'), ] def save(self, *args, **kwargs):