From 553f170f89b41320b65a1a82faebda30b5375a8c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 1 Nov 2022 18:04:27 -0700 Subject: [PATCH] Only show editions with the author on the author page --- bookwyrm/models/book.py | 4 ++++ bookwyrm/templates/author/author.html | 3 ++- bookwyrm/templatetags/book_display_tags.py | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index 190046019..5bef5c1ee 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -241,6 +241,10 @@ class Work(OrderedCollectionPageMixin, Book): """in case the default edition is not set""" return self.editions.order_by("-edition_rank").first() + def author_edition(self, author): + """in case the default edition doesn't have the required author""" + return self.editions.filter(authors=author).order_by("-edition_rank").first() + def to_edition_list(self, **kwargs): """an ordered collection of editions""" return self.to_ordered_collection( diff --git a/bookwyrm/templates/author/author.html b/bookwyrm/templates/author/author.html index 1d87dee96..f186c0f6e 100644 --- a/bookwyrm/templates/author/author.html +++ b/bookwyrm/templates/author/author.html @@ -3,6 +3,7 @@ {% load markdown %} {% load humanize %} {% load utilities %} +{% load book_display_tags %} {% block title %}{{ author.name }}{% endblock %} @@ -141,7 +142,7 @@

{% blocktrans with name=author.name %}Books by {{ name }}{% endblocktrans %}

{% for book in books %} - {% with book=book.default_edition %} + {% with book=book|author_edition:author %}
{% include 'landing/small-book.html' with book=book %} diff --git a/bookwyrm/templatetags/book_display_tags.py b/bookwyrm/templatetags/book_display_tags.py index 2ae900c9e..049a2b256 100644 --- a/bookwyrm/templatetags/book_display_tags.py +++ b/bookwyrm/templatetags/book_display_tags.py @@ -20,3 +20,9 @@ def get_book_description(book): def get_book_file_links(book): """links for a book""" return book.file_links.filter(domain__status="approved") + + +@register.filter(name="author_edition") +def get_author_edition(book, author): + """default edition for a book on the author page""" + return book.author_edition(author)