(De)serializers for tag fields
This commit is contained in:
@ -7,38 +7,7 @@ from model_utils.managers import InheritanceManager
|
||||
from bookwyrm import activitypub
|
||||
from .base_model import ActivitypubMixin, OrderedCollectionPageMixin
|
||||
from .base_model import ActivityMapping, BookWyrmModel, PrivacyLevels
|
||||
|
||||
|
||||
# --- Formatters ----- #
|
||||
def ap_book_tags(mention_books):
|
||||
''' convert books into tags field '''
|
||||
tags = []
|
||||
for book in mention_books.all():
|
||||
tags.append(activitypub.Link(
|
||||
href=book.remote_id,
|
||||
name=book.title,
|
||||
type='Book'
|
||||
))
|
||||
return tags
|
||||
|
||||
def ap_user_tags(mention_users):
|
||||
''' convert users into tag fields '''
|
||||
tags = []
|
||||
for user in mention_users.all():
|
||||
tags.append(activitypub.Mention(
|
||||
href=user.remote_id,
|
||||
name=user.username,
|
||||
))
|
||||
return tags
|
||||
|
||||
|
||||
def model_book_tags(activity_tags):
|
||||
''' grab the tagged books out of the activity '''
|
||||
pass
|
||||
|
||||
def model_user_tags():
|
||||
''' create user mentions '''
|
||||
pass
|
||||
from .base_model import tag_formatter
|
||||
|
||||
|
||||
class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||
@ -89,24 +58,6 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||
''' structured replies block '''
|
||||
return self.to_replies()
|
||||
|
||||
@property
|
||||
def ap_tag(self):
|
||||
''' references to books and/or users '''
|
||||
tags = []
|
||||
for book in self.mention_books.all():
|
||||
tags.append(activitypub.Link(
|
||||
href=book.remote_id,
|
||||
name=book.title,
|
||||
type='Book'
|
||||
))
|
||||
for user in self.mention_users.all():
|
||||
tags.append(activitypub.Mention(
|
||||
href=user.remote_id,
|
||||
name=user.username,
|
||||
))
|
||||
return tags
|
||||
|
||||
|
||||
@property
|
||||
def ap_status_image(self):
|
||||
''' attach a book cover, if relevent '''
|
||||
@ -126,9 +77,16 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||
ActivityMapping('to', 'ap_to'),
|
||||
ActivityMapping('cc', 'ap_cc'),
|
||||
ActivityMapping('replies', 'ap_replies'),
|
||||
ActivityMapping('tag', 'mention_books', ap_book_tags, model_book_tags),
|
||||
# since one activitypub field populates two model fields, we do this
|
||||
ActivityMapping('tag', 'mention_users', ap_user_tags, model_user_tags),
|
||||
ActivityMapping(
|
||||
'tag', 'mention_books',
|
||||
lambda x: tag_formatter(x, 'title', 'Book'),
|
||||
activitypub.tag_formatter
|
||||
),
|
||||
ActivityMapping(
|
||||
'tag', 'mention_users',
|
||||
lambda x: tag_formatter(x, 'username', 'Mention'),
|
||||
activitypub.tag_formatter
|
||||
),
|
||||
]
|
||||
|
||||
# serializing to bookwyrm expanded activitypub
|
||||
|
Reference in New Issue
Block a user