mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-25 02:51:13 +00:00
Merge pull request #3353 from dato/fix_quotation_str_pagenum
Fix creation of quotations with no end position
This commit is contained in:
commit
70f803a1f6
2 changed files with 13 additions and 8 deletions
|
@ -392,10 +392,10 @@ class Quotation(BookStatus):
|
|||
def _format_position(self) -> Optional[str]:
|
||||
"""serialize page position"""
|
||||
beg = self.position
|
||||
end = self.endposition or 0
|
||||
end = self.endposition
|
||||
if self.position_mode != "PG" or not beg:
|
||||
return None
|
||||
return f"pp. {beg}-{end}" if end > beg else f"p. {beg}"
|
||||
return f"pp. {beg}-{end}" if end else f"p. {beg}"
|
||||
|
||||
@property
|
||||
def pure_content(self):
|
||||
|
|
|
@ -340,8 +340,11 @@ class Status(TestCase):
|
|||
def test_quotation_page_serialization(self, *_):
|
||||
"""serialization of quotation page position"""
|
||||
tests = [
|
||||
("single pos", 7, None, "p. 7"),
|
||||
("page range", 7, 10, "pp. 7-10"),
|
||||
("single pos", "7", "", "p. 7"),
|
||||
("missing beg", "", "10", None),
|
||||
("page range", "7", "10", "pp. 7-10"),
|
||||
("page range roman", "xv", "xvi", "pp. xv-xvi"),
|
||||
("page range reverse", "14", "10", "pp. 14-10"),
|
||||
]
|
||||
for desc, beg, end, pages in tests:
|
||||
with self.subTest(desc):
|
||||
|
@ -355,10 +358,12 @@ class Status(TestCase):
|
|||
position_mode="PG",
|
||||
)
|
||||
activity = status.to_activity(pure=True)
|
||||
self.assertRegex(
|
||||
activity["content"],
|
||||
f'^<p>"my quote"</p> <p>— <a .+</a>, {pages}</p>$',
|
||||
)
|
||||
if pages:
|
||||
pages_re = re.escape(pages)
|
||||
expect_re = f'^<p>"my quote"</p> <p>— <a .+</a>, {pages_re}</p>$'
|
||||
else:
|
||||
expect_re = '^<p>"my quote"</p> <p>— <a .+</a></p>$'
|
||||
self.assertRegex(activity["content"], expect_re)
|
||||
|
||||
def test_review_to_activity(self, *_):
|
||||
"""subclass of the base model version with a "pure" serializer"""
|
||||
|
|
Loading…
Reference in a new issue