1
0
Fork 0

Use endposition when serializing Quotation

This commit is contained in:
Adeodato Simó 2023-09-17 01:40:23 -03:00
parent 1322a0c693
commit ce3885d4f6
No known key found for this signature in database
GPG key ID: CDF447845F1A986F
2 changed files with 34 additions and 2 deletions

View file

@ -1,5 +1,6 @@
""" models for storing different kinds of Activities """
from dataclasses import MISSING
from typing import Optional
import re
from django.apps import apps
@ -351,14 +352,22 @@ class Quotation(BookStatus):
blank=True,
)
def _format_position(self) -> Optional[str]:
"""serialize page position"""
beg = self.position
end = self.endposition or 0
if self.position_mode != "PG" or not beg:
return None
return f"pp. {beg}-{end}" if end > beg else f"p. {beg}"
@property
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):
citation += f", p. {self.position}"
if position := self._format_position():
citation += f", {position}"
return f"{quote} <p>{citation}</p>{self.content}"
activity_serializer = activitypub.Quotation