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