Fixes list item fields and broadcast updates
This commit is contained in:
		| @@ -361,12 +361,11 @@ class CollectionItemMixin(ActivitypubMixin): | |||||||
|  |  | ||||||
|     def save(self, *args, broadcast=True, **kwargs): |     def save(self, *args, broadcast=True, **kwargs): | ||||||
|         """ broadcast updated """ |         """ broadcast updated """ | ||||||
|         created = not bool(self.id) |  | ||||||
|         # first off, we want to save normally no matter what |         # first off, we want to save normally no matter what | ||||||
|         super().save(*args, **kwargs) |         super().save(*args, **kwargs) | ||||||
|  |  | ||||||
|         # these shouldn't be edited, only created and deleted |         # list items can be updateda, normally you would only broadcast on created | ||||||
|         if not broadcast or not created or not self.user.local: |         if not broadcast or not self.user.local: | ||||||
|             return |             return | ||||||
|  |  | ||||||
|         # adding an obj to the collection |         # adding an obj to the collection | ||||||
| @@ -384,7 +383,7 @@ class CollectionItemMixin(ActivitypubMixin): | |||||||
|         """ AP for shelving a book""" |         """ AP for shelving a book""" | ||||||
|         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="{:s}#add".format(collection_field.remote_id), | ||||||
|             actor=user.remote_id, |             actor=user.remote_id, | ||||||
|             object=self.to_activity_dataclass(), |             object=self.to_activity_dataclass(), | ||||||
|             target=collection_field.remote_id, |             target=collection_field.remote_id, | ||||||
| @@ -394,7 +393,7 @@ class CollectionItemMixin(ActivitypubMixin): | |||||||
|         """ AP for un-shelving a book""" |         """ AP for un-shelving a book""" | ||||||
|         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="{:s}#remove".format(collection_field.remote_id), | ||||||
|             actor=user.remote_id, |             actor=user.remote_id, | ||||||
|             object=self.to_activity_dataclass(), |             object=self.to_activity_dataclass(), | ||||||
|             target=collection_field.remote_id, |             target=collection_field.remote_id, | ||||||
|   | |||||||
| @@ -59,10 +59,10 @@ class ListItem(CollectionItemMixin, BookWyrmModel): | |||||||
|     """ ok """ |     """ ok """ | ||||||
|  |  | ||||||
|     book = fields.ForeignKey( |     book = fields.ForeignKey( | ||||||
|         "Edition", on_delete=models.PROTECT, activitypub_field="object" |         "Edition", on_delete=models.PROTECT, activitypub_field="book" | ||||||
|     ) |     ) | ||||||
|     book_list = fields.ForeignKey( |     book_list = models.ForeignKey( | ||||||
|         "List", on_delete=models.CASCADE, activitypub_field="target" |         "List", on_delete=models.CASCADE | ||||||
|     ) |     ) | ||||||
|     user = fields.ForeignKey( |     user = fields.ForeignKey( | ||||||
|         "User", on_delete=models.PROTECT, activitypub_field="actor" |         "User", on_delete=models.PROTECT, activitypub_field="actor" | ||||||
|   | |||||||
| @@ -32,7 +32,6 @@ 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 """ | ||||||
| @@ -67,16 +66,17 @@ class ShelfBook(CollectionItemMixin, BookWyrmModel): | |||||||
|     """ many to many join table for books and shelves """ |     """ many to many join table for books and shelves """ | ||||||
|  |  | ||||||
|     book = fields.ForeignKey( |     book = fields.ForeignKey( | ||||||
|         "Edition", on_delete=models.PROTECT, activitypub_field="object" |         "Edition", on_delete=models.PROTECT, activitypub_field="book" | ||||||
|     ) |     ) | ||||||
|     shelf = fields.ForeignKey( |     shelf = models.ForeignKey( | ||||||
|         "Shelf", on_delete=models.PROTECT, activitypub_field="target" |         "Shelf", on_delete=models.PROTECT | ||||||
|     ) |     ) | ||||||
|     user = fields.ForeignKey( |     user = fields.ForeignKey( | ||||||
|         "User", on_delete=models.PROTECT, activitypub_field="actor" |         "User", on_delete=models.PROTECT, activitypub_field="actor" | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|     activity_serializer = activitypub.ShelfItem |     activity_serializer = activitypub.ShelfItem | ||||||
|  |     collection_field = "shelf" | ||||||
|  |  | ||||||
|     def save(self, *args, **kwargs): |     def save(self, *args, **kwargs): | ||||||
|         if not self.user: |         if not self.user: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user