Serialize links for books
This commit is contained in:
@ -234,7 +234,10 @@ class Work(OrderedCollectionPageMixin, Book):
|
||||
)
|
||||
|
||||
activity_serializer = activitypub.Work
|
||||
serialize_reverse_fields = [("editions", "editions", "-edition_rank")]
|
||||
serialize_reverse_fields = [
|
||||
("editions", "editions", "-edition_rank"),
|
||||
("file_links", "fileLinks", "-created_date"),
|
||||
]
|
||||
deserialize_reverse_fields = [("editions", "editions"), ("file_links", "fileLinks")]
|
||||
|
||||
|
||||
@ -289,6 +292,8 @@ class Edition(Book):
|
||||
|
||||
activity_serializer = activitypub.Edition
|
||||
name_field = "title"
|
||||
serialize_reverse_fields = [("file_links", "fileLinks", "-created_date")]
|
||||
deserialize_reverse_fields = [("file_links", "fileLinks")]
|
||||
|
||||
def get_rank(self):
|
||||
"""calculate how complete the data is on this edition"""
|
||||
|
@ -23,11 +23,15 @@ class Link(ActivitypubMixin, BookWyrmModel):
|
||||
del kwargs["broadcast"]
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
def to_activity(self, omit=(), **kwargs):
|
||||
"""we don't need ALL the fields"""
|
||||
return super().to_activity(omit=("@context", "id"), **kwargs)
|
||||
|
||||
|
||||
class FileLink(Link):
|
||||
"""a link to a file"""
|
||||
|
||||
book = fields.ForeignKey(
|
||||
book = models.ForeignKey(
|
||||
"Book", on_delete=models.CASCADE, related_name="file_links", null=True
|
||||
)
|
||||
filetype = fields.CharField(max_length=5, activitypub_field="mediaType")
|
||||
|
@ -344,6 +344,7 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
"""deactivate rather than delete a user"""
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
self.is_active = False
|
||||
# skip the logic in this class's save()
|
||||
super().save(*args, **kwargs)
|
||||
@ -404,14 +405,6 @@ class KeyPair(ActivitypubMixin, BookWyrmModel):
|
||||
self.private_key, self.public_key = create_key_pair()
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
def to_activity(self, **kwargs):
|
||||
"""override default AP serializer to add context object
|
||||
idk if this is the best way to go about this"""
|
||||
activity_object = super().to_activity(**kwargs)
|
||||
del activity_object["@context"]
|
||||
del activity_object["type"]
|
||||
return activity_object
|
||||
|
||||
|
||||
class AnnualGoal(BookWyrmModel):
|
||||
"""set a goal for how many books you read in a year"""
|
||||
|
Reference in New Issue
Block a user