Merge pull request #2325 from bookwyrm-social/author-page-editions

Only show editions with the author on the author page
This commit is contained in:
Mouse Reeve 2022-11-01 18:18:58 -07:00 committed by GitHub
commit c16155aa41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View file

@ -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(

View file

@ -3,6 +3,7 @@
{% load markdown %}
{% load humanize %}
{% load utilities %}
{% load book_display_tags %}
{% block title %}{{ author.name }}{% endblock %}
@ -141,7 +142,7 @@
<h2 class="title is-4">{% blocktrans with name=author.name %}Books by {{ name }}{% endblocktrans %}</h2>
<div class="columns is-multiline is-mobile">
{% for book in books %}
{% with book=book.default_edition %}
{% with book=book|author_edition:author %}
<div class="column is-one-fifth-tablet is-half-mobile is-flex is-flex-direction-column">
<div class="is-flex-grow-1">
{% include 'landing/small-book.html' with book=book %}

View file

@ -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)