mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
parent
b072bd50d5
commit
fd077f482a
1 changed files with 18 additions and 2 deletions
|
@ -1,6 +1,8 @@
|
||||||
''' status serializers '''
|
''' status serializers '''
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
|
from fedireads.settings import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
def get_review(review):
|
def get_review(review):
|
||||||
''' fedireads json for book reviews '''
|
''' fedireads json for book reviews '''
|
||||||
|
@ -50,6 +52,21 @@ def get_status(status):
|
||||||
uri = status.absolute_id
|
uri = status.absolute_id
|
||||||
reply_parent_id = status.reply_parent.absolute_id \
|
reply_parent_id = status.reply_parent.absolute_id \
|
||||||
if status.reply_parent else None
|
if status.reply_parent else None
|
||||||
|
|
||||||
|
image_attachments = []
|
||||||
|
books = list(status.mention_books.all()[:3])
|
||||||
|
if hasattr(status, 'book'):
|
||||||
|
books.append(status.book)
|
||||||
|
for book in books:
|
||||||
|
if book and book.cover:
|
||||||
|
image_path = book.cover.url
|
||||||
|
image_type = image_path.split('.')[-1]
|
||||||
|
image_attachments.append({
|
||||||
|
'type': 'Document',
|
||||||
|
'mediaType': 'image/%s' % image_type,
|
||||||
|
'url': 'https://%s%s' % (DOMAIN, image_path),
|
||||||
|
'name': 'Cover of "%s"' % book.title,
|
||||||
|
})
|
||||||
status_json = {
|
status_json = {
|
||||||
'id': uri,
|
'id': uri,
|
||||||
'url': uri,
|
'url': uri,
|
||||||
|
@ -62,7 +79,7 @@ def get_status(status):
|
||||||
'sensitive': status.sensitive,
|
'sensitive': status.sensitive,
|
||||||
'content': status.content,
|
'content': status.content,
|
||||||
'type': status.activity_type,
|
'type': status.activity_type,
|
||||||
'attachment': [], # TODO: the book cover
|
'attachment': image_attachments,
|
||||||
'replies': {
|
'replies': {
|
||||||
'id': '%s/replies' % uri,
|
'id': '%s/replies' % uri,
|
||||||
'type': 'Collection',
|
'type': 'Collection',
|
||||||
|
@ -81,7 +98,6 @@ def get_status(status):
|
||||||
def get_replies(status, replies):
|
def get_replies(status, replies):
|
||||||
''' collection of replies '''
|
''' collection of replies '''
|
||||||
id_slug = status.absolute_id + '/replies'
|
id_slug = status.absolute_id + '/replies'
|
||||||
# TODO only partially implemented
|
|
||||||
return {
|
return {
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
'id': id_slug,
|
'id': id_slug,
|
||||||
|
|
Loading…
Reference in a new issue