Check if a book is already shelved after import
This commit is contained in:
parent
3344eed3b9
commit
8c8aae2c92
|
@ -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,22 +166,24 @@ 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
|
||||||
for read in item.reads:
|
for read in item.reads:
|
||||||
read.book = item.book
|
read.book = item.book
|
||||||
read.user = user
|
read.user = user
|
||||||
read.save()
|
read.save()
|
||||||
|
|
||||||
if include_reviews and (item.rating or item.review):
|
if include_reviews and (item.rating or item.review):
|
||||||
review_title = 'Review of {!r} on Goodreads'.format(
|
review_title = 'Review of {!r} on Goodreads'.format(
|
||||||
|
|
Loading…
Reference in New Issue