def field_to_activity(self, value): tags = [] for item in value.all(): activity_type = item.__class__.__name__ if activity_type == 'User': activity_type = 'Mention' tags.append(activitypub.Link( href=item.remote_id, name=getattr(item, item.name_field), type=activity_type )) return tags
def field_from_activity(self, value): if not isinstance(value, list): return None items = [] for link_json in value: link = activitypub.Link(**link_json) tag_type = link.type if link.type != 'Mention' else 'Person' if tag_type != self.related_model.activity_serializer.type: # tags can contain multiple types continue items.append( activitypub.resolve_remote_id(self.related_model, link.href) ) return items
def ap_tag(self): ''' references to books and/or users ''' tags = [] for book in self.mention_books.all(): tags.append( activitypub.Link(href=book.local_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