From 25fd7276ea23d69a707414eb874363601cdcc433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Sun, 17 Sep 2023 10:46:11 -0300 Subject: [PATCH] `pure_content()` refactor: shorter conditionals --- bookwyrm/models/status.py | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index e51f2ba07..8c98028a0 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -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}

(comment on ' - f'"{self.book.title}", page {self.progress})

' - ) - else: - return_value = ( - f'{self.content}

(comment on ' - f'"{self.book.title}")

' - ) - return return_value + progress = self.progress or 0 + citation = ( + f'comment on ' + f'"{self.book.title}"' + ) + if self.progress_mode == "PG" and progress > 0: + citation += f", page {progress}" + return f"{self.content}

({citation})

" 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"^

", '

"', self.quote) quote = re.sub(r"

$", '"

', quote) + citation = f'-- "{self.book.title}"' if self.position_mode == "PG" and self.position and (self.position > 0): - return_value = ( - f'{quote}

-- ' - f'"{self.book.title}", page {self.position}

{self.content}' - ) - else: - return_value = ( - f'{quote}

-- ' - f'"{self.book.title}"

{self.content}' - ) - return return_value + citation += f", page {self.position}" + return f"{quote}

{citation}

{self.content}" activity_serializer = activitypub.Quotation