From a679a46bcac0bbc06348cf5acda43b203a78701c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 4 Aug 2021 12:36:54 -0700 Subject: [PATCH] Limit authors displayed in status --- bookwyrm/templates/snippets/authors.html | 19 +++++++++++++++++-- bookwyrm/templates/snippets/book_titleby.html | 9 ++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/snippets/authors.html b/bookwyrm/templates/snippets/authors.html index 476956b6..5584417d 100644 --- a/bookwyrm/templates/snippets/authors.html +++ b/bookwyrm/templates/snippets/authors.html @@ -1,9 +1,16 @@ {% spaceless %} +{% load i18n %} +{% load humanize %} {% comment %} @todo The author property needs to be an Organization or a Person. We’ll be using Thing which is the more generic ancestor. @see https://schema.org/Author {% endcomment %} -{% for author in book.authors.all %} +{% firstof limit None as limit %} +{% with subtraction_value='-'|add:limit %} +{% with remainder_count=book.authors.count|add:subtraction_value %} +{% with remainder_count_display=remainder_count|intcomma %} + +{% for author in book.authors.all|slice:limit %} {{ author.name }}{% if not forloop.last %}, {% endif %} + >{{ author.name }}{% if not forloop.last %}, {% elif remainder_count > 0 %}, {% blocktrans trimmed count counter=remainder_count %} +and {{ remainder_count_display }} other +{% plural %} +and {{ remainder_count_display }} others +{% endblocktrans %}{% endif %} {% endfor %} + +{% endwith %} +{% endwith %} +{% endwith %} {% endspaceless %} diff --git a/bookwyrm/templates/snippets/book_titleby.html b/bookwyrm/templates/snippets/book_titleby.html index 353f9d12..5eddabff 100644 --- a/bookwyrm/templates/snippets/book_titleby.html +++ b/bookwyrm/templates/snippets/book_titleby.html @@ -1,8 +1,15 @@ {% load i18n %} {% load utilities %} +{% spaceless %} + {% if book.authors %} -{% blocktrans with path=book.local_path title=book|book_title %}{{ title }} by {% endblocktrans %}{% include 'snippets/authors.html' with book=book %} +{% blocktrans trimmed with path=book.local_path title=book|book_title %} +{{ title }} by +{% endblocktrans %} +{% include 'snippets/authors.html' with book=book limit=3 %} + {% else %} {{ book|book_title }} {% endif %} +{% endspaceless %}