mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
Include author name when serializing Quotation
This commit is contained in:
parent
fadf30b942
commit
80a1180090
2 changed files with 25 additions and 1 deletions
|
@ -366,7 +366,8 @@ class Quotation(BookStatus):
|
|||
quote = re.sub(r"^<p>", '<p>"', self.quote)
|
||||
quote = re.sub(r"</p>$", '"</p>', quote)
|
||||
title, href = self.book.title, self.book.remote_id
|
||||
citation = f'— <a href="{href}"><i>{title}</i></a>'
|
||||
author = f"{name}: " if (name := self.book.author_text) else ""
|
||||
citation = f'— {author}<a href="{href}"><i>{title}</i></a>'
|
||||
if position := self._format_position():
|
||||
citation += f", {position}"
|
||||
return f"{quote} <p>{citation}</p>{self.content}"
|
||||
|
|
|
@ -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 <p>— Author Name: <a href="{self.book.remote_id}">'
|
||||
"<i>Test Edition</i></a></p>"
|
||||
),
|
||||
)
|
||||
self.assertEqual(
|
||||
activity["attachment"][0]["name"], "Author Name: Test Edition (worm)"
|
||||
)
|
||||
|
||||
def test_quotation_page_serialization(self, *_):
|
||||
"""serialization of quotation page position"""
|
||||
tests = [
|
||||
|
|
Loading…
Reference in a new issue