Only import reviews if we're importing the book. (Avoid generating duplicate reviews.)

This commit is contained in:
Adam Kelly 2020-04-29 16:13:09 +01:00
parent 4f9edae05a
commit 62a3891ecf
2 changed files with 11 additions and 14 deletions

View file

@ -27,7 +27,6 @@ def import_data(job_id):
job = ImportJob.objects.get(id=job_id) job = ImportJob.objects.get(id=job_id)
try: try:
results = [] results = []
reviews = []
for item in job.items.all(): for item in job.items.all():
try: try:
item.resolve() item.resolve()
@ -36,24 +35,11 @@ def import_data(job_id):
if item.book: if item.book:
item.save() item.save()
results.append(item) results.append(item)
if item.rating or item.review:
reviews.append(item)
else: else:
item.fail_reason = "Could not match book on OpenLibrary" item.fail_reason = "Could not match book on OpenLibrary"
item.save() item.save()
status = outgoing.handle_import_books(job.user, results) 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: if status:
job.import_status = status job.import_status = status
job.save() job.save()

View file

@ -192,6 +192,17 @@ def handle_import_books(user, items):
activity = activitypub.get_add(user, item.book, desired_shelf) activity = activitypub.get_add(user, item.book, desired_shelf)
broadcast(user, activity) 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: for read in item.reads:
read.book = item.book read.book = item.book
read.user = user read.user = user