From fa0f37fb0fa90abaf4a8db91f4ed6b838ae55618 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 29 Jan 2020 15:32:43 -0800 Subject: [PATCH] Format descriptions --- fedireads/templates/book.html | 18 +++++++----------- fedireads/templates/feed.html | 5 ++--- fedireads/templates/user.html | 2 +- fedireads/templatetags/fr_display.py | 15 ++++++++++++++- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/fedireads/templates/book.html b/fedireads/templates/book.html index 1ebf0e48b..bb76cc5fb 100644 --- a/fedireads/templates/book.html +++ b/fedireads/templates/book.html @@ -8,24 +8,20 @@

{{ book.data.title }}

by {{ book.authors.first.data.name }} {{ rating | stars }} {{ rating }} -
{{ book.data.description }}
+
{{ book.data.description | description }}
- -

Leave a review

- + +
+

Reviews

+ {% if not reviews %} +

No reviews yet!

+ {% endif %}
{% csrf_token %} {{ review_form.as_p }}
-
- -
-

Reviews

- {% if not reviews %} -

No reviews yet!

- {% endif %} {% for review in reviews %}

{{ review.name }} diff --git a/fedireads/templates/feed.html b/fedireads/templates/feed.html index 45b09d28a..ffbb2b830 100644 --- a/fedireads/templates/feed.html +++ b/fedireads/templates/feed.html @@ -86,7 +86,7 @@ {{ activity.book.data.title }} by {{ activity.book.authors.first.data.name }} -
{{ activity.book.data.description }}
+
{{ activity.book.data.description | description }}

@@ -100,11 +100,10 @@ {{ activity.book.data.title }} by {{ activity.book.authors.first.data.name }} -
{{ activity.book.data.description }}

{{ activity.name }}

-

{{ activity.rating | stars }} stars

+

{{ activity.rating | stars }}

{{ activity.review_content }}

diff --git a/fedireads/templates/user.html b/fedireads/templates/user.html index 72fa6864a..53fb2a94b 100644 --- a/fedireads/templates/user.html +++ b/fedireads/templates/user.html @@ -60,7 +60,7 @@
{% for shelf in shelves %}
-

{{ shelf.shelf.name }}

+

{{ shelf.name }}

{% if shelf.books %} diff --git a/fedireads/templatetags/fr_display.py b/fedireads/templatetags/fr_display.py index 952a2b3f3..a112b4369 100644 --- a/fedireads/templatetags/fr_display.py +++ b/fedireads/templatetags/fr_display.py @@ -11,5 +11,18 @@ def dict_key(d, k): @register.filter(name='stars') def stars(number): ''' turn integers into stars ''' - number = int(number) + try: + number = int(number) + except TypeError: + number = 0 return ('★' * number) + '☆' * (5 - number) + +@register.filter(name='description') +def description_format(description): + ''' handle the various OL description formats ''' + if isinstance(description, dict) and 'value' in description: + description = description['value'] + if '----------' in description: + description = description.split('----------')[0] + + return description.strip()