Check for existing reviews/ratings on import items

This commit is contained in:
Mouse Reeve 2021-11-14 07:50:19 -08:00
parent bdc3f6828b
commit 2748e0a824

View file

@ -171,21 +171,25 @@ def handle_imported_book(item):
read.user = user read.user = user
read.save() read.save()
if job.include_reviews and (item.rating or item.review): if job.include_reviews and (item.rating or item.review) and not item.linked_review:
# we don't know the publication date of the review, # we don't know the publication date of the review,
# but "now" is a bad guess # but "now" is a bad guess
published_date_guess = item.date_read or item.date_added published_date_guess = item.date_read or item.date_added
if item.review: if item.review:
# pylint: disable=consider-using-f-string # pylint: disable=consider-using-f-string
review_title = ( review_title = "Review of {!r} on {!r}".format(
"Review of {!r} on {!r}".format( item.book.title,
item.book.title, job.source,
job.source,
)
if item.review
else ""
) )
review = models.Review( existing = models.Review.objects.filter(
user=user,
book=item.book,
name=review_title,
rating=item.rating,
published_date=published_date_guess,
).first()
review = existing or models.Review(
user=user, user=user,
book=item.book, book=item.book,
name=review_title, name=review_title,
@ -196,13 +200,20 @@ def handle_imported_book(item):
) )
else: else:
# just a rating # just a rating
review = models.ReviewRating( existing = models.ReviewRating.objects.filter(
user=user,
book=item.book,
published_date=published_date_guess,
rating=item.rating,
).first()
review = existing or models.ReviewRating(
user=user, user=user,
book=item.book, book=item.book,
rating=item.rating, rating=item.rating,
published_date=published_date_guess, published_date=published_date_guess,
privacy=job.privacy, privacy=job.privacy,
) )
# only broadcast this review to other bookwyrm instances # only broadcast this review to other bookwyrm instances
review.save(software="bookwyrm", priority=LOW) review.save(software="bookwyrm", priority=LOW)
item.linked_review = review item.linked_review = review