From 4de9989d8e88d45de260d7aeb07ded7612d5bd28 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 5 Jun 2022 16:02:25 +1000 Subject: [PATCH] add page numbers to comment and quote statuses This adds the page number for quote and comment statuses where a page number is provided: - all ActivityPub posts - Explore cards for comments (quotes already have the page number) This responds to #2136 --- bookwyrm/models/status.py | 30 ++++++++++++++----- .../snippets/status/content_status.html | 3 ++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index f37076b5c..3949e09a9 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -303,10 +303,17 @@ class Comment(BookStatus): @property def pure_content(self): """indicate the book in question for mastodon (or w/e) users""" - return ( - f'{self.content}

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

' - ) + 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 activity_serializer = activitypub.Comment @@ -332,10 +339,17 @@ 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) - return ( - f'{quote}

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

{self.content}' - ) + 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 activity_serializer = activitypub.Quotation diff --git a/bookwyrm/templates/snippets/status/content_status.html b/bookwyrm/templates/snippets/status/content_status.html index bee4af1dc..d0d385153 100644 --- a/bookwyrm/templates/snippets/status/content_status.html +++ b/bookwyrm/templates/snippets/status/content_status.html @@ -112,6 +112,9 @@ {% with full=status.content|safe no_trim=status.content_warning itemprop="reviewBody" %} {% include 'snippets/trimmed_text.html' %} {% endwith %} + {% if status.progress %} +
{% trans "page" %} {{ status.progress }}
+ {% endif %} {% endif %} {% if status.attachments.exists %}