mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-18 15:41:12 +00:00
Fixes list item fields and broadcast updates
This commit is contained in:
parent
af58455ae9
commit
e550f8cde6
3 changed files with 11 additions and 12 deletions
|
@ -361,12 +361,11 @@ class CollectionItemMixin(ActivitypubMixin):
|
|||
|
||||
def save(self, *args, broadcast=True, **kwargs):
|
||||
""" broadcast updated """
|
||||
created = not bool(self.id)
|
||||
# first off, we want to save normally no matter what
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
# these shouldn't be edited, only created and deleted
|
||||
if not broadcast or not created or not self.user.local:
|
||||
# list items can be updateda, normally you would only broadcast on created
|
||||
if not broadcast or not self.user.local:
|
||||
return
|
||||
|
||||
# adding an obj to the collection
|
||||
|
@ -384,7 +383,7 @@ class CollectionItemMixin(ActivitypubMixin):
|
|||
""" AP for shelving a book"""
|
||||
collection_field = getattr(self, self.collection_field)
|
||||
return activitypub.Add(
|
||||
id=self.get_remote_id(),
|
||||
id="{:s}#add".format(collection_field.remote_id),
|
||||
actor=user.remote_id,
|
||||
object=self.to_activity_dataclass(),
|
||||
target=collection_field.remote_id,
|
||||
|
@ -394,7 +393,7 @@ class CollectionItemMixin(ActivitypubMixin):
|
|||
""" AP for un-shelving a book"""
|
||||
collection_field = getattr(self, self.collection_field)
|
||||
return activitypub.Remove(
|
||||
id=self.get_remote_id(),
|
||||
id="{:s}#remove".format(collection_field.remote_id),
|
||||
actor=user.remote_id,
|
||||
object=self.to_activity_dataclass(),
|
||||
target=collection_field.remote_id,
|
||||
|
|
|
@ -59,10 +59,10 @@ class ListItem(CollectionItemMixin, BookWyrmModel):
|
|||
""" ok """
|
||||
|
||||
book = fields.ForeignKey(
|
||||
"Edition", on_delete=models.PROTECT, activitypub_field="object"
|
||||
"Edition", on_delete=models.PROTECT, activitypub_field="book"
|
||||
)
|
||||
book_list = fields.ForeignKey(
|
||||
"List", on_delete=models.CASCADE, activitypub_field="target"
|
||||
book_list = models.ForeignKey(
|
||||
"List", on_delete=models.CASCADE
|
||||
)
|
||||
user = fields.ForeignKey(
|
||||
"User", on_delete=models.PROTECT, activitypub_field="actor"
|
||||
|
|
|
@ -32,7 +32,6 @@ class Shelf(OrderedCollectionMixin, BookWyrmModel):
|
|||
)
|
||||
|
||||
activity_serializer = activitypub.Shelf
|
||||
collection_field = "shelf"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
""" set the identifier """
|
||||
|
@ -67,16 +66,17 @@ class ShelfBook(CollectionItemMixin, BookWyrmModel):
|
|||
""" many to many join table for books and shelves """
|
||||
|
||||
book = fields.ForeignKey(
|
||||
"Edition", on_delete=models.PROTECT, activitypub_field="object"
|
||||
"Edition", on_delete=models.PROTECT, activitypub_field="book"
|
||||
)
|
||||
shelf = fields.ForeignKey(
|
||||
"Shelf", on_delete=models.PROTECT, activitypub_field="target"
|
||||
shelf = models.ForeignKey(
|
||||
"Shelf", on_delete=models.PROTECT
|
||||
)
|
||||
user = fields.ForeignKey(
|
||||
"User", on_delete=models.PROTECT, activitypub_field="actor"
|
||||
)
|
||||
|
||||
activity_serializer = activitypub.ShelfItem
|
||||
collection_field = "shelf"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.user:
|
||||
|
|
Loading…
Reference in a new issue