From 80a1180090cd23f7629dd261a7fe9c63e477661d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Mon, 25 Sep 2023 15:03:52 -0300 Subject: [PATCH] Include author name when serializing Quotation --- bookwyrm/models/status.py | 3 ++- bookwyrm/tests/models/test_status_model.py | 23 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 5d6109468..11646431b 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -366,7 +366,8 @@ class Quotation(BookStatus): quote = re.sub(r"^

", '

"', self.quote) quote = re.sub(r"

$", '"

', quote) title, href = self.book.title, self.book.remote_id - citation = f'— {title}' + author = f"{name}: " if (name := self.book.author_text) else "" + citation = f'— {author}{title}' if position := self._format_position(): citation += f", {position}" return f"{quote}

{citation}

{self.content}" diff --git a/bookwyrm/tests/models/test_status_model.py b/bookwyrm/tests/models/test_status_model.py index 760849f28..d1f07b44e 100644 --- a/bookwyrm/tests/models/test_status_model.py +++ b/bookwyrm/tests/models/test_status_model.py @@ -314,6 +314,29 @@ class Status(TestCase): ) self.assertEqual(activity["attachment"][0]["name"], "Test Edition") + def test_quotation_with_author_to_pure_activity(self, *_): + """serialization of quotation of a book with author and edition info""" + self.book.authors.set([models.Author.objects.create(name="Author Name")]) + self.book.physical_format = "worm" + self.book.save() + status = models.Quotation.objects.create( + quote="quote", + content="", + user=self.local_user, + book=self.book, + ) + activity = status.to_activity(pure=True) + self.assertEqual( + activity["content"], + ( + f'quote

— Author Name: ' + "Test Edition

" + ), + ) + self.assertEqual( + activity["attachment"][0]["name"], "Author Name: Test Edition (worm)" + ) + def test_quotation_page_serialization(self, *_): """serialization of quotation page position""" tests = [