pure_content() refactor: shorter conditionals

This commit is contained in:
Adeodato Simó 2023-09-17 10:46:11 -03:00
parent a09b2ab45c
commit 25fd7276ea
No known key found for this signature in database
GPG key ID: CDF447845F1A986F

View file

@ -320,17 +320,14 @@ class Comment(BookStatus):
@property
def pure_content(self):
"""indicate the book in question for mastodon (or w/e) users"""
if self.progress_mode == "PG" and self.progress and (self.progress > 0):
return_value = (
f'{self.content}<p>(comment on <a href="{self.book.remote_id}">'
f'"{self.book.title}"</a>, page {self.progress})</p>'
)
else:
return_value = (
f'{self.content}<p>(comment on <a href="{self.book.remote_id}">'
f'"{self.book.title}"</a>)</p>'
)
return return_value
progress = self.progress or 0
citation = (
f'comment on <a href="{self.book.remote_id}">'
f'"{self.book.title}"</a>'
)
if self.progress_mode == "PG" and progress > 0:
citation += f", page {progress}"
return f"{self.content}<p>({citation})</p>"
activity_serializer = activitypub.Comment
@ -359,17 +356,10 @@ class Quotation(BookStatus):
"""indicate the book in question for mastodon (or w/e) users"""
quote = re.sub(r"^<p>", '<p>"', self.quote)
quote = re.sub(r"</p>$", '"</p>', quote)
citation = f'-- <a href="{self.book.remote_id}">"{self.book.title}"</a>'
if self.position_mode == "PG" and self.position and (self.position > 0):
return_value = (
f'{quote} <p>-- <a href="{self.book.remote_id}">'
f'"{self.book.title}"</a>, page {self.position}</p>{self.content}'
)
else:
return_value = (
f'{quote} <p>-- <a href="{self.book.remote_id}">'
f'"{self.book.title}"</a></p>{self.content}'
)
return return_value
citation += f", page {self.position}"
return f"{quote} <p>{citation}</p>{self.content}"
activity_serializer = activitypub.Quotation