Fix merge weirdness around shelve/unshelve
This commit is contained in:
parent
54f1b0aee2
commit
32f044445f
@ -373,28 +373,20 @@ def add_statuses_on_shelve(sender, instance, *args, **kwargs):
|
|||||||
"""update books stream when user shelves a book"""
|
"""update books stream when user shelves a book"""
|
||||||
if not instance.user.local:
|
if not instance.user.local:
|
||||||
return
|
return
|
||||||
|
book = None
|
||||||
|
if hasattr(instance, "book"):
|
||||||
|
book = instance.book
|
||||||
|
elif instance.mention_books.exists():
|
||||||
|
book = instance.mention_books.first()
|
||||||
|
if not book:
|
||||||
|
return
|
||||||
|
|
||||||
# check if the book is already on the user's shelves
|
# check if the book is already on the user's shelves
|
||||||
if models.ShelfBook.objects.filter(
|
editions = book.parent_work.editions.all()
|
||||||
user=instance.user, book__in=instance.book.parent_work.editions.all()
|
if models.ShelfBook.objects.filter(user=instance.user, book__in=editions).exists():
|
||||||
).exists():
|
|
||||||
return
|
return
|
||||||
|
|
||||||
BooksStream().add_book_statuses(instance.user, instance.book)
|
BooksStream().add_book_statuses(instance.user, book)
|
||||||
|
|
||||||
|
|
||||||
@receiver(signals.post_delete, sender=models.ShelfBook)
|
|
||||||
# pylint: disable=unused-argument
|
|
||||||
def remove_statuses_on_shelve(sender, instance, *args, **kwargs):
|
|
||||||
"""update books stream when user unshelves a book"""
|
|
||||||
if not instance.user.local:
|
|
||||||
return
|
|
||||||
# check if the book is actually unshelved, not just moved
|
|
||||||
if models.ShelfBook.objects.filter(
|
|
||||||
user=instance.user, book__in=instance.book.parent_work.editions.all()
|
|
||||||
).exists():
|
|
||||||
return
|
|
||||||
|
|
||||||
BooksStream().remove_book_statuses(instance.user, instance.book)
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(signals.post_delete, sender=models.ShelfBook)
|
@receiver(signals.post_delete, sender=models.ShelfBook)
|
||||||
@ -421,6 +413,7 @@ def remove_statuses_on_unshelve(sender, instance, *args, **kwargs):
|
|||||||
|
|
||||||
# ---- TASKS
|
# ---- TASKS
|
||||||
|
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
def populate_stream_task(stream, user_id):
|
def populate_stream_task(stream, user_id):
|
||||||
"""background task for populating an empty activitystream"""
|
"""background task for populating an empty activitystream"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user