From 9ba0aec6d914137e8b12b3250279f5ae2119763b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 23 Apr 2021 14:58:48 -0700 Subject: [PATCH 1/3] Show subtitles when titles are very short --- bookwyrm/templates/snippets/book_titleby.html | 5 +++-- bookwyrm/templates/snippets/status/status_header.html | 4 ++-- bookwyrm/templatetags/bookwyrm_tags.py | 8 ++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/bookwyrm/templates/snippets/book_titleby.html b/bookwyrm/templates/snippets/book_titleby.html index e561a8a33..80127fb72 100644 --- a/bookwyrm/templates/snippets/book_titleby.html +++ b/bookwyrm/templates/snippets/book_titleby.html @@ -1,7 +1,8 @@ {% load i18n %} +{% load bookwyrm_tags %} {% if book.authors %} -{% blocktrans with path=book.local_path title=book.title %}{{ title }} by {% endblocktrans %}{% include 'snippets/authors.html' with book=book %} +{% blocktrans with path=book.local_path title=book|title %}{{ title }} by {% endblocktrans %}{% include 'snippets/authors.html' with book=book %} {% else %} -{{ book.title }} +{{ book|title }} {% endif %} diff --git a/bookwyrm/templates/snippets/status/status_header.html b/bookwyrm/templates/snippets/status/status_header.html index 0fa74ddd1..7a04b44a3 100644 --- a/bookwyrm/templates/snippets/status/status_header.html +++ b/bookwyrm/templates/snippets/status/status_header.html @@ -43,7 +43,7 @@ {% if status.book %} {% if status.status_type == 'GeneratedNote' or status.status_type == 'Rating' %} - {{ status.book.title }}{% if status.status_type == 'Rating' %}: + {{ status.book|title }}{% if status.status_type == 'Rating' %}: {{ status.mention_books.first.title }} + {{ status.mention_books.first|title }} {% endif %} {% if status.progress %} diff --git a/bookwyrm/templatetags/bookwyrm_tags.py b/bookwyrm/templatetags/bookwyrm_tags.py index 649a0dfa1..0180d1e05 100644 --- a/bookwyrm/templatetags/bookwyrm_tags.py +++ b/bookwyrm/templatetags/bookwyrm_tags.py @@ -167,6 +167,14 @@ def get_next_shelf(current_shelf): return "read" return "to-read" +@register.filter(name="title") +def get_title(book): + """ display the subtitle if the title is short """ + title = book.title + if len(title) < 6 and book.subtitle: + title = "{:s}: {:s}".format(title, book.subtitle) + return title + @register.simple_tag(takes_context=False) def related_status(notification): From a49925916373cf9f4b791746ee6f4240ccc5b93f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 23 Apr 2021 15:01:35 -0700 Subject: [PATCH 2/3] Fixes python formatting --- bookwyrm/templatetags/bookwyrm_tags.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/templatetags/bookwyrm_tags.py b/bookwyrm/templatetags/bookwyrm_tags.py index 0180d1e05..2d95904f0 100644 --- a/bookwyrm/templatetags/bookwyrm_tags.py +++ b/bookwyrm/templatetags/bookwyrm_tags.py @@ -167,6 +167,7 @@ def get_next_shelf(current_shelf): return "read" return "to-read" + @register.filter(name="title") def get_title(book): """ display the subtitle if the title is short """ From 179ba241155592045b8cb9b1674d9c194c2f8a4f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 23 Apr 2021 15:29:55 -0700 Subject: [PATCH 3/3] Safely handle invalid book --- bookwyrm/templatetags/bookwyrm_tags.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bookwyrm/templatetags/bookwyrm_tags.py b/bookwyrm/templatetags/bookwyrm_tags.py index 2d95904f0..bd14a410f 100644 --- a/bookwyrm/templatetags/bookwyrm_tags.py +++ b/bookwyrm/templatetags/bookwyrm_tags.py @@ -171,6 +171,8 @@ def get_next_shelf(current_shelf): @register.filter(name="title") def get_title(book): """ display the subtitle if the title is short """ + if not book: + return "" title = book.title if len(title) < 6 and book.subtitle: title = "{:s}: {:s}".format(title, book.subtitle)