Add Status.page_image property

This commit is contained in:
Bart Schuurmans 2024-01-20 17:18:50 +01:00
parent f7b4d9ea50
commit ad56024ffe

View file

@ -190,6 +190,15 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
"""description of the page in meta tags when only this status is shown"""
return None
@property
def page_image(self):
"""image to use as preview in meta tags when only this status is shown"""
if self.mention_books.exists():
book = self.mention_books.first()
return book.preview_image
else:
return self.user.preview_image
def to_replies(self, **kwargs):
"""helper function for loading AP serialized replies to a status"""
return self.to_ordered_collection(
@ -313,6 +322,10 @@ class BookStatus(Status):
abstract = True
@property
def page_image(self):
return self.book.preview_image or super().page_image
class Comment(BookStatus):
"""like a review but without a rating and transient"""