Merge pull request #156 from cthulahoops/duplicate_reviews

Only import reviews if we're importing the book. (Avoid generating du…
This commit is contained in:
Mouse Reeve 2020-04-29 11:38:18 -07:00 committed by GitHub
commit 6b86bf32cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 14 deletions

View file

@ -29,7 +29,6 @@ def import_data(job_id):
job = ImportJob.objects.get(id=job_id)
try:
results = []
reviews = []
for item in job.items.all():
try:
item.resolve()
@ -38,24 +37,11 @@ def import_data(job_id):
if item.book:
item.save()
results.append(item)
if item.rating or item.review:
reviews.append(item)
else:
item.fail_reason = "Could not match book on OpenLibrary"
item.save()
status = outgoing.handle_import_books(job.user, results)
for item in reviews:
review_title = "Review of {!r} on Goodreads".format(
item.book.title,
) if item.review else ""
outgoing.handle_review(
job.user,
item.book,
review_title,
item.review,
item.rating,
)
if status:
job.import_status = status
job.save()

View file

@ -192,6 +192,17 @@ def handle_import_books(user, items):
activity = activitypub.get_add(user, item.book, desired_shelf)
broadcast(user, activity)
if item.rating or item.review:
review_title = "Review of {!r} on Goodreads".format(
item.book.title,
) if item.review else ""
handle_review(
user,
item.book,
review_title,
item.review,
item.rating,
)
for read in item.reads:
read.book = item.book
read.user = user