From a56855d5e4b03f3232b36b3dfe012eebb20ad42f Mon Sep 17 00:00:00 2001 From: Logan Buckley Date: Wed, 17 Jun 2020 18:16:19 -0400 Subject: [PATCH] Implement and use Author.display_name --- fedireads/models/book.py | 11 +++++++++++ fedireads/templates/author.html | 4 ++-- fedireads/templates/snippets/authors.html | 2 +- fedireads/templates/snippets/shelf.html | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/fedireads/models/book.py b/fedireads/models/book.py index ca198584..a6877739 100644 --- a/fedireads/models/book.py +++ b/fedireads/models/book.py @@ -184,3 +184,14 @@ class Author(FedireadsModel): @property def activitypub_serialize(self): return activitypub.get_author(self) + + @property + def display_name(self): + ''' Helper to return a displayable name''' + if self.name: + return name + # don't want to return a spurious space if all of these are None + elif self.first_name and self.last_name: + return self.first_name + ' ' + self.last_name + else: + return self.last_name or self.first_name diff --git a/fedireads/templates/author.html b/fedireads/templates/author.html index f9da61d0..39148909 100644 --- a/fedireads/templates/author.html +++ b/fedireads/templates/author.html @@ -2,7 +2,7 @@ {% load fr_display %} {% block content %}
-

{{ author.name }}

+

{{ author.display_name }}

{% if author.bio %}

@@ -12,7 +12,7 @@

-

Books by {{ author.name }}

+

Books by {{ author.display_name }}

{% for book in books %}
diff --git a/fedireads/templates/snippets/authors.html b/fedireads/templates/snippets/authors.html index e8106f5d..165c4cda 100644 --- a/fedireads/templates/snippets/authors.html +++ b/fedireads/templates/snippets/authors.html @@ -1 +1 @@ -{{ book.authors.first.name }} +{{ book.authors.first.display_name }} diff --git a/fedireads/templates/snippets/shelf.html b/fedireads/templates/snippets/shelf.html index 990e11bc..7f094232 100644 --- a/fedireads/templates/snippets/shelf.html +++ b/fedireads/templates/snippets/shelf.html @@ -42,7 +42,7 @@ {{ book.title }} - {{ book.authors.first.name }} + {{ book.authors.first.display_name }} {% if book.first_published_date %}{{ book.first_published_date }}{% endif %}