mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-22 17:41:08 +00:00
Merge pull request #791 from mouse-reeve/review-pure-title
Fixes review name in pure serialization
This commit is contained in:
commit
4f22657dc2
5 changed files with 68 additions and 11 deletions
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{% load i18n %}{% load humanize %}
|
||||
|
||||
{% blocktrans with title=book.title path=book.remote_id rating=rating count counter=rating %}Rated <em><a href="{{ path }}">{{ title }}</a></em>: {{ rating }} star{% plural %}Rated <em><a href="{{ path }}">{{ title }}</a></em>: {{ rating }} stars{% endblocktrans %}
|
||||
{% blocktrans with title=book.title path=book.remote_id display_rating=rating|floatformat:"0" count counter=rating %}Rated <em><a href="{{ path }}">{{ title }}</a></em>: {{ display_rating }} star{% plural %}Rated <em><a href="{{ path }}">{{ title }}</a></em>: {{ display_rating }} stars{% endblocktrans %}
|
||||
|
|
|
@ -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 <em>{{ book_title }}</em> ({{ display_rating }} star): {{ review_title }}{% plural %}Review of <em>{{ book_title }}</em> ({{ display_rating }} stars): {{ review_title }}{% endblocktrans %}
|
||||
|
||||
{% else %}
|
||||
|
||||
{% blocktrans with book_title=book.title review_title=name %}Review of <em>{{ book_title }}</em>: {{ review_title }}{% endblocktrans %}
|
||||
|
||||
{% endif %}
|
|
@ -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 <em>%s</em> (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 <em>%s</em>: 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 <em><a href="%s">%s</a></em>: 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
|
||||
|
|
Loading…
Reference in a new issue