mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-21 14:38:08 +00:00
Check if a book is already shelved after import
This commit is contained in:
parent
3344eed3b9
commit
8c8aae2c92
2 changed files with 13 additions and 11 deletions
|
@ -205,7 +205,7 @@ def get_data(url):
|
||||||
'User-Agent': settings.USER_AGENT,
|
'User-Agent': settings.USER_AGENT,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
except RequestError:
|
except (RequestError, SSLError):
|
||||||
raise ConnectorException()
|
raise ConnectorException()
|
||||||
if not resp.ok:
|
if not resp.ok:
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
|
|
@ -166,15 +166,17 @@ def handle_imported_book(user, item, include_reviews, privacy):
|
||||||
if not item.book:
|
if not item.book:
|
||||||
return
|
return
|
||||||
|
|
||||||
if item.shelf:
|
existing_shelf = models.ShelfBook.objects.filter(
|
||||||
|
book=item.book, added_by=user).exists()
|
||||||
|
|
||||||
|
# shelve the book if it hasn't been shelved already
|
||||||
|
if item.shelf and not existing_shelf:
|
||||||
desired_shelf = models.Shelf.objects.get(
|
desired_shelf = models.Shelf.objects.get(
|
||||||
identifier=item.shelf,
|
identifier=item.shelf,
|
||||||
user=user
|
user=user
|
||||||
)
|
)
|
||||||
# shelve the book if it hasn't been shelved already
|
shelf_book = models.ShelfBook.objects.create(
|
||||||
shelf_book, created = models.ShelfBook.objects.get_or_create(
|
|
||||||
book=item.book, shelf=desired_shelf, added_by=user)
|
book=item.book, shelf=desired_shelf, added_by=user)
|
||||||
if created:
|
|
||||||
broadcast(user, shelf_book.to_add_activity(user), privacy=privacy)
|
broadcast(user, shelf_book.to_add_activity(user), privacy=privacy)
|
||||||
|
|
||||||
# only add new read-throughs if the item isn't already shelved
|
# only add new read-throughs if the item isn't already shelved
|
||||||
|
|
Loading…
Reference in a new issue