Skip to content

Commit

Permalink
pure_content() refactor: shorter conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
dato committed Sep 17, 2023
1 parent a09b2ab commit 25fd727
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions bookwyrm/models/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -359,17 +356,10 @@ def pure_content(self):
"""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

Expand Down

0 comments on commit 25fd727

Please sign in to comment.