diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py
index 247c6aca..e034d59e 100644
--- a/bookwyrm/models/fields.py
+++ b/bookwyrm/models/fields.py
@@ -448,3 +448,8 @@ class IntegerField(ActivitypubFieldMixin, models.IntegerField):
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 0ddcfd17..adc9d39d 100644
--- a/bookwyrm/models/status.py
+++ b/bookwyrm/models/status.py
@@ -304,13 +304,10 @@ 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": self.rating, "name": self.name}
+ ).strip()
@property
def pure_content(self):
diff --git a/bookwyrm/templates/snippets/generated_status/rating.html b/bookwyrm/templates/snippets/generated_status/rating.html
index 13afd94d..b70171cd 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 display_rating=rating|floatformat:"0" count counter=rating %}Rated {{ title }}: {{ display_rating }} star{% plural %}Rated {{ title }}: {{ display_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
new file mode 100644
index 00000000..a8d3fa5b
--- /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 display_rating=rating|floatformat:"0" review_title=name count counter=rating %}Review of {{ book_title }} ({{ display_rating }} star): {{ review_title }}{% plural %}Review of {{ book_title }} ({{ display_rating }} stars): {{ review_title }}{% endblocktrans %}
+
+{% else %}
+
+{% blocktrans with book_title=book.title review_title=name %}Review of {{ book_title }}: {{ review_title }}{% endblocktrans %}
+
+{% endif %}
diff --git a/bookwyrm/tests/models/test_status_model.py b/bookwyrm/tests/models/test_status_model.py
index 54fe7fee..97df315f 100644
--- a/bookwyrm/tests/models/test_status_model.py
+++ b/bookwyrm/tests/models/test_status_model.py
@@ -252,7 +252,7 @@ class Status(TestCase):
status = models.Review.objects.create(
name="Review name",
content="test content",
- rating=3,
+ rating=3.0,
user=self.local_user,
book=self.book,
)
@@ -269,7 +269,7 @@ class Status(TestCase):
status = models.Review.objects.create(
name="Review name",
content="test content",
- rating=3,
+ rating=3.0,
user=self.local_user,
book=self.book,
)
@@ -277,7 +277,8 @@ class Status(TestCase):
self.assertEqual(activity["id"], status.remote_id)
self.assertEqual(activity["type"], "Article")
self.assertEqual(
- activity["name"], 'Review of "%s" (3 stars): Review name' % self.book.title
+ activity["name"],
+ "Review of %s (3 stars): Review name" % self.book.title,
)
self.assertEqual(activity["content"], "test content")
self.assertEqual(activity["attachment"][0].type, "Document")
@@ -287,6 +288,50 @@ class Status(TestCase):
)
self.assertEqual(activity["attachment"][0].name, "Test Edition")
+ def test_review_to_pure_activity_no_rating(self, *_):
+ """ subclass of the base model version with a "pure" serializer """
+ status = models.Review.objects.create(
+ name="Review name",
+ content="test content",
+ user=self.local_user,
+ book=self.book,
+ )
+ activity = status.to_activity(pure=True)
+ self.assertEqual(activity["id"], status.remote_id)
+ self.assertEqual(activity["type"], "Article")
+ self.assertEqual(
+ activity["name"], "Review of %s: Review name" % self.book.title
+ )
+ self.assertEqual(activity["content"], "test content")
+ self.assertEqual(activity["attachment"][0].type, "Document")
+ self.assertEqual(
+ activity["attachment"][0].url,
+ "https://%s%s" % (settings.DOMAIN, self.book.cover.url),
+ )
+ self.assertEqual(activity["attachment"][0].name, "Test Edition")
+
+ def test_reviewrating_to_pure_activity(self, *_):
+ """ subclass of the base model version with a "pure" serializer """
+ status = models.ReviewRating.objects.create(
+ rating=3.0,
+ user=self.local_user,
+ book=self.book,
+ )
+ activity = status.to_activity(pure=True)
+ self.assertEqual(activity["id"], status.remote_id)
+ self.assertEqual(activity["type"], "Note")
+ self.assertEqual(
+ activity["content"],
+ 'Rated %s: 3 stars'
+ % (self.book.remote_id, self.book.title),
+ )
+ self.assertEqual(activity["attachment"][0].type, "Document")
+ self.assertEqual(
+ activity["attachment"][0].url,
+ "https://%s%s" % (settings.DOMAIN, self.book.cover.url),
+ )
+ self.assertEqual(activity["attachment"][0].name, "Test Edition")
+
def test_favorite(self, *_):
""" fav a status """
real_broadcast = models.Favorite.broadcast