From fe67f6530739592a35dd6c17160244613bcd127f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 11 Jan 2021 10:25:34 -0800 Subject: [PATCH] Set default edition on bookwyrm import --- bookwyrm/connectors/bookwyrm_connector.py | 6 +++++- bookwyrm/models/book.py | 6 ++++-- bookwyrm/views.py | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bookwyrm/connectors/bookwyrm_connector.py b/bookwyrm/connectors/bookwyrm_connector.py index 3c6f4614..1f877993 100644 --- a/bookwyrm/connectors/bookwyrm_connector.py +++ b/bookwyrm/connectors/bookwyrm_connector.py @@ -7,7 +7,11 @@ class Connector(AbstractMinimalConnector): ''' this is basically just for search ''' def get_or_create_book(self, remote_id): - return activitypub.resolve_remote_id(models.Edition, remote_id) + edition = activitypub.resolve_remote_id(models.Edition, remote_id) + work = edition.parent_work + work.default_edition = work.get_default_edition() + work.save() + return edition def parse_search_data(self, data): return data diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index 70d81800..07d1d5dc 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -131,12 +131,14 @@ class Work(OrderedCollectionPageMixin, Book): def get_default_edition(self): ''' in case the default edition is not set ''' - return self.default_edition or self.editions.first() + return self.default_edition or self.editions.order_by( + '-edition_rank' + ).first() def to_edition_list(self, **kwargs): ''' an ordered collection of editions ''' return self.to_ordered_collection( - self.editions.order_by('-updated_date').all(), + self.editions.order_by('-edition_rank').all(), remote_id='%s/editions' % self.remote_id, **kwargs ) diff --git a/bookwyrm/views.py b/bookwyrm/views.py index cc45bfb2..faacd2ff 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -736,7 +736,7 @@ def editions_page(request, book_id): data = { 'title': 'Editions of %s' % work.title, - 'editions': work.editions.all(), + 'editions': work.editions.order_by('-edition_rank').all(), 'work': work, } return TemplateResponse(request, 'editions.html', data)