From bde6ce8525c6d16205a5a4bd784fbf83572e9783 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 24 Mar 2021 09:31:45 -0700 Subject: [PATCH] Fixes review name in pure serialization --- bookwyrm/models/fields.py | 3 +++ bookwyrm/models/status.py | 15 +++++++-------- .../generated_status/review_pure_name.html | 10 ++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 bookwyrm/templates/snippets/generated_status/review_pure_name.html diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index 247c6aca..a5985e8d 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -448,3 +448,6 @@ class IntegerField(ActivitypubFieldMixin, models.IntegerField): class DecimalField(ActivitypubFieldMixin, models.DecimalField): """ activitypub-aware boolean field """ + + def field_to_activity(self, value): + return float(value) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 0ddcfd17..56f30020 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -304,13 +304,12 @@ class Review(Status): @property def pure_name(self): """ clarify review names for mastodon serialization """ - if self.rating: - return 'Review of "{}" ({:d} stars): {}'.format( - self.book.title, - self.rating, - self.name, - ) - return 'Review of "{}": {}'.format(self.book.title, self.name) + template = get_template("snippets/generated_status/review_pure_name.html") + return template.render({ + "book": self.book, + "rating": int(self.rating), + "name": self.name + }).strip() @property def pure_content(self): @@ -332,7 +331,7 @@ class ReviewRating(Review): @property def pure_content(self): template = get_template("snippets/generated_status/rating.html") - return template.render({"book": self.book, "rating": self.rating}).strip() + return template.render({"book": self.book, "rating": int(self.rating)}).strip() activity_serializer = activitypub.Rating pure_type = "Note" diff --git a/bookwyrm/templates/snippets/generated_status/review_pure_name.html b/bookwyrm/templates/snippets/generated_status/review_pure_name.html new file mode 100644 index 00000000..3c133678 --- /dev/null +++ b/bookwyrm/templates/snippets/generated_status/review_pure_name.html @@ -0,0 +1,10 @@ +{% 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 %} + +{% else %} + +{% blocktrans with book_title=book.title review_title=name %}Review of {{ book_title }}: {{ review_title }}{% endblocktrans %} + +{% endif %}