mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 00:26:33 +00:00
Update ordered collection classes to use CollectionItem
This commit is contained in:
parent
98161b9041
commit
31077a9790
3 changed files with 13 additions and 17 deletions
|
@ -64,6 +64,7 @@ class ActivitypubMixin:
|
||||||
)
|
)
|
||||||
if hasattr(self, "property_fields"):
|
if hasattr(self, "property_fields"):
|
||||||
self.activity_fields += [
|
self.activity_fields += [
|
||||||
|
# pylint: disable=cell-var-from-loop
|
||||||
PropertyField(lambda a, o: set_activity_from_property_field(a, o, f))
|
PropertyField(lambda a, o: set_activity_from_property_field(a, o, f))
|
||||||
for f in self.property_fields
|
for f in self.property_fields
|
||||||
]
|
]
|
||||||
|
@ -356,8 +357,7 @@ class OrderedCollectionMixin(OrderedCollectionPageMixin):
|
||||||
class CollectionItemMixin(ActivitypubMixin):
|
class CollectionItemMixin(ActivitypubMixin):
|
||||||
""" for items that are part of an (Ordered)Collection """
|
""" for items that are part of an (Ordered)Collection """
|
||||||
|
|
||||||
activity_serializer = activitypub.Add
|
activity_serializer = activitypub.CollectionItem
|
||||||
object_field = collection_field = None
|
|
||||||
|
|
||||||
def save(self, *args, broadcast=True, **kwargs):
|
def save(self, *args, broadcast=True, **kwargs):
|
||||||
""" broadcast updated """
|
""" broadcast updated """
|
||||||
|
@ -370,35 +370,33 @@ class CollectionItemMixin(ActivitypubMixin):
|
||||||
return
|
return
|
||||||
|
|
||||||
# adding an obj to the collection
|
# adding an obj to the collection
|
||||||
activity = self.to_add_activity()
|
activity = self.to_add_activity(self.user)
|
||||||
self.broadcast(activity, self.user)
|
self.broadcast(activity, self.user)
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
""" broadcast a remove activity """
|
""" broadcast a remove activity """
|
||||||
activity = self.to_remove_activity()
|
activity = self.to_remove_activity(self.user)
|
||||||
super().delete(*args, **kwargs)
|
super().delete(*args, **kwargs)
|
||||||
if self.user.local:
|
if self.user.local:
|
||||||
self.broadcast(activity, self.user)
|
self.broadcast(activity, self.user)
|
||||||
|
|
||||||
def to_add_activity(self):
|
def to_add_activity(self, user):
|
||||||
""" AP for shelving a book"""
|
""" AP for shelving a book"""
|
||||||
object_field = getattr(self, self.object_field)
|
|
||||||
collection_field = getattr(self, self.collection_field)
|
collection_field = getattr(self, self.collection_field)
|
||||||
return activitypub.Add(
|
return activitypub.Add(
|
||||||
id=self.get_remote_id(),
|
id=self.get_remote_id(),
|
||||||
actor=self.user.remote_id,
|
actor=user.remote_id,
|
||||||
object=object_field,
|
object=self.to_activity_dataclass(),
|
||||||
target=collection_field.remote_id,
|
target=collection_field.remote_id,
|
||||||
).serialize()
|
).serialize()
|
||||||
|
|
||||||
def to_remove_activity(self):
|
def to_remove_activity(self, user):
|
||||||
""" AP for un-shelving a book"""
|
""" AP for un-shelving a book"""
|
||||||
object_field = getattr(self, self.object_field)
|
|
||||||
collection_field = getattr(self, self.collection_field)
|
collection_field = getattr(self, self.collection_field)
|
||||||
return activitypub.Remove(
|
return activitypub.Remove(
|
||||||
id=self.get_remote_id(),
|
id=self.get_remote_id(),
|
||||||
actor=self.user.remote_id,
|
actor=user.remote_id,
|
||||||
object=object_field,
|
object=self.to_activity_dataclass(),
|
||||||
target=collection_field.remote_id,
|
target=collection_field.remote_id,
|
||||||
).serialize()
|
).serialize()
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,7 @@ class ListItem(CollectionItemMixin, BookWyrmModel):
|
||||||
order = fields.IntegerField(blank=True, null=True)
|
order = fields.IntegerField(blank=True, null=True)
|
||||||
endorsement = models.ManyToManyField("User", related_name="endorsers")
|
endorsement = models.ManyToManyField("User", related_name="endorsers")
|
||||||
|
|
||||||
activity_serializer = activitypub.Add
|
activity_serializer = activitypub.ListItem
|
||||||
object_field = "book"
|
|
||||||
collection_field = "book_list"
|
collection_field = "book_list"
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
|
|
@ -32,6 +32,7 @@ class Shelf(OrderedCollectionMixin, BookWyrmModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
activity_serializer = activitypub.Shelf
|
activity_serializer = activitypub.Shelf
|
||||||
|
collection_field = "shelf"
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
""" set the identifier """
|
""" set the identifier """
|
||||||
|
@ -75,9 +76,7 @@ class ShelfBook(CollectionItemMixin, BookWyrmModel):
|
||||||
"User", on_delete=models.PROTECT, activitypub_field="actor"
|
"User", on_delete=models.PROTECT, activitypub_field="actor"
|
||||||
)
|
)
|
||||||
|
|
||||||
activity_serializer = activitypub.Add
|
activity_serializer = activitypub.ShelfItem
|
||||||
object_field = "book"
|
|
||||||
collection_field = "shelf"
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.user:
|
if not self.user:
|
||||||
|
|
Loading…
Reference in a new issue