From 1d53a06e35dd5b89e1deb0fcf5e458fe1b9d76c0 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 24 Mar 2021 09:51:49 -0700 Subject: [PATCH] Fixes decimaal formatting --- bookwyrm/models/fields.py | 2 ++ bookwyrm/models/status.py | 4 ++-- bookwyrm/templates/snippets/generated_status/rating.html | 2 +- .../templates/snippets/generated_status/review_pure_name.html | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index a5985e8d..e034d59e 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -450,4 +450,6 @@ class DecimalField(ActivitypubFieldMixin, models.DecimalField): """ activitypub-aware boolean field """ def field_to_activity(self, value): + if not value: + return None return float(value) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index e655616f..adc9d39d 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -306,7 +306,7 @@ class Review(Status): """ clarify review names for mastodon serialization """ template = get_template("snippets/generated_status/review_pure_name.html") return template.render( - {"book": self.book, "rating": int(self.rating), "name": self.name} + {"book": self.book, "rating": self.rating, "name": self.name} ).strip() @property @@ -329,7 +329,7 @@ class ReviewRating(Review): @property def pure_content(self): template = get_template("snippets/generated_status/rating.html") - return template.render({"book": self.book, "rating": int(self.rating)}).strip() + return template.render({"book": self.book, "rating": self.rating}).strip() activity_serializer = activitypub.Rating pure_type = "Note" diff --git a/bookwyrm/templates/snippets/generated_status/rating.html b/bookwyrm/templates/snippets/generated_status/rating.html index 13afd94d..c23d0eb8 100644 --- a/bookwyrm/templates/snippets/generated_status/rating.html +++ b/bookwyrm/templates/snippets/generated_status/rating.html @@ -1,3 +1,3 @@ {% load i18n %}{% load humanize %} -{% blocktrans with title=book.title path=book.remote_id rating=rating count counter=rating %}Rated {{ title }}: {{ rating }} star{% plural %}Rated {{ title }}: {{ rating }} stars{% endblocktrans %} +{% blocktrans with title=book.title path=book.remote_id rating=rating|floatformat:"0" count counter=rating %}Rated {{ title }}: {{ rating }} star{% plural %}Rated {{ title }}: {{ rating }} stars{% endblocktrans %} diff --git a/bookwyrm/templates/snippets/generated_status/review_pure_name.html b/bookwyrm/templates/snippets/generated_status/review_pure_name.html index 3c133678..f5864384 100644 --- a/bookwyrm/templates/snippets/generated_status/review_pure_name.html +++ b/bookwyrm/templates/snippets/generated_status/review_pure_name.html @@ -1,7 +1,7 @@ {% load i18n %} {% if rating %} -{% blocktrans with book_title=book.title rating=rating review_title=name count counter=rating %}Review of {{ book_title }} ({{ rating }} star): {{ review_title }}{% plural %}Review of {{ book_title }} ({{ rating }} stars): {{ review_title }}{% endblocktrans %} +{% blocktrans with book_title=book.title rating=rating|floatformat:"0" review_title=name count counter=rating %}Review of {{ book_title }} ({{ rating }} star): {{ review_title }}{% plural %}Review of {{ book_title }} ({{ rating }} stars): {{ review_title }}{% endblocktrans %} {% else %}