From 6bf9a7159b917f3ee63b78e96faaa37963e32df6 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 4 Nov 2020 13:09:11 -0800 Subject: [PATCH 1/3] Load expanded book data from bookwyrm connector --- bookwyrm/connectors/bookwyrm_connector.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/bookwyrm/connectors/bookwyrm_connector.py b/bookwyrm/connectors/bookwyrm_connector.py index c7a0f2ec..d962f235 100644 --- a/bookwyrm/connectors/bookwyrm_connector.py +++ b/bookwyrm/connectors/bookwyrm_connector.py @@ -3,6 +3,7 @@ from uuid import uuid4 from django.core.exceptions import ObjectDoesNotExist from django.core.files.base import ContentFile +from django.db import transaction import requests from bookwyrm import models @@ -114,5 +115,22 @@ class Connector(AbstractConnector): def expand_book_data(self, book): - # TODO - pass + work = book + # go from the edition to the work, if necessary + if isinstance(book, models.Edition): + work = book.parent_work + + # it may be that we actually want to request this url + editions_url = '%s/editions' % work.remote_id + edition_options = get_data(editions_url) + for edition_data in edition_options: + with transaction.atomic(): + edition = self.create_book( + edition_data['id'], + edition_data, + models.Edition + ) + edition.parent_work = work + edition.save() + if not edition.authors.exists() and work.authors.exists(): + edition.authors.set(work.authors.all()) From 9238f4c74a9e1e3fc870bb0dec07b5e350876292 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 4 Nov 2020 13:18:30 -0800 Subject: [PATCH 2/3] Correclty parse ordered collection json for editions --- bookwyrm/connectors/bookwyrm_connector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/connectors/bookwyrm_connector.py b/bookwyrm/connectors/bookwyrm_connector.py index d962f235..6a1432f8 100644 --- a/bookwyrm/connectors/bookwyrm_connector.py +++ b/bookwyrm/connectors/bookwyrm_connector.py @@ -121,9 +121,9 @@ class Connector(AbstractConnector): work = book.parent_work # it may be that we actually want to request this url - editions_url = '%s/editions' % work.remote_id + editions_url = '%s/editions?page=true' % work.remote_id edition_options = get_data(editions_url) - for edition_data in edition_options: + for edition_data in edition_options['orderedItems']: with transaction.atomic(): edition = self.create_book( edition_data['id'], From 19a9136ebbf2e830d2b3fc1b2b378c3ab6a31755 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 4 Nov 2020 13:31:44 -0800 Subject: [PATCH 3/3] Correctly serialize edition ids in work page --- bookwyrm/models/book.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index 04a8b286..484f6824 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -2,6 +2,7 @@ import re from django.db import models +from django.db.models import Q from django.utils import timezone from model_utils.managers import InheritanceManager @@ -149,7 +150,12 @@ class Work(OrderedCollectionPageMixin, Book): @property def editions_path(self): ''' it'd be nice to serialize the edition instead but, recursion ''' - return [e.remote_id for e in self.edition_set.all()] + default = self.default_edition + ed_list = [ + e.local_id for e in self.edition_set.filter(~Q(id=default.id)).all() + ] + return [default.local_id] + ed_list + def to_edition_list(self, **kwargs): ''' activitypub serialization for this work's editions '''