mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-28 20:41:46 +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]:
|
def _format_position(self) -> Optional[str]:
|
||||||
"""serialize page position"""
|
"""serialize page position"""
|
||||||
beg = self.position
|
beg = self.position
|
||||||
end = self.endposition or 0
|
end = self.endposition
|
||||||
if self.position_mode != "PG" or not beg:
|
if self.position_mode != "PG" or not beg:
|
||||||
return None
|
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
|
@property
|
||||||
def pure_content(self):
|
def pure_content(self):
|
||||||
|
|
|
@ -340,8 +340,11 @@ class Status(TestCase):
|
||||||
def test_quotation_page_serialization(self, *_):
|
def test_quotation_page_serialization(self, *_):
|
||||||
"""serialization of quotation page position"""
|
"""serialization of quotation page position"""
|
||||||
tests = [
|
tests = [
|
||||||
("single pos", 7, None, "p. 7"),
|
("single pos", "7", "", "p. 7"),
|
||||||
("page range", 7, 10, "pp. 7-10"),
|
("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:
|
for desc, beg, end, pages in tests:
|
||||||
with self.subTest(desc):
|
with self.subTest(desc):
|
||||||
|
@ -355,10 +358,12 @@ class Status(TestCase):
|
||||||
position_mode="PG",
|
position_mode="PG",
|
||||||
)
|
)
|
||||||
activity = status.to_activity(pure=True)
|
activity = status.to_activity(pure=True)
|
||||||
self.assertRegex(
|
if pages:
|
||||||
activity["content"],
|
pages_re = re.escape(pages)
|
||||||
f'^<p>"my quote"</p> <p>— <a .+</a>, {pages}</p>$',
|
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, *_):
|
def test_review_to_activity(self, *_):
|
||||||
"""subclass of the base model version with a "pure" serializer"""
|
"""subclass of the base model version with a "pure" serializer"""
|
||||||
|
|
Loading…
Reference in a new issue