Associate imported review with import item

This commit is contained in:
Mouse Reeve 2021-11-13 11:44:05 -08:00
parent 1e2dca402b
commit 1e46de4c9d
4 changed files with 35 additions and 0 deletions

View file

@ -205,3 +205,5 @@ def handle_imported_book(item):
)
# only broadcast this review to other bookwyrm instances
review.save(software="bookwyrm", priority=LOW)
item.linked_review = review
item.save()

View file

@ -0,0 +1,24 @@
# Generated by Django 3.2.5 on 2021-11-13 19:35
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0114_importjob_source"),
]
operations = [
migrations.AddField(
model_name="importitem",
name="linked_review",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="bookwyrm.review",
),
),
]

View file

@ -60,6 +60,9 @@ class ImportItem(models.Model):
related_name="book_guess",
)
fail_reason = models.TextField(null=True)
linked_review = models.ForeignKey(
"Review", on_delete=models.SET_NULL, null=True, blank=True
)
def resolve(self):
"""try various ways to lookup a book"""

View file

@ -233,6 +233,9 @@ class GenericImporter(TestCase):
self.assertEqual(review.rating, 2.0)
self.assertEqual(review.privacy, "unlisted")
import_item.refresh_from_db()
self.assertEqual(import_item.linked_review, review)
@patch("bookwyrm.activitystreams.add_status_task.delay")
def test_handle_imported_book_rating(self, *_):
"""rating import"""
@ -250,6 +253,9 @@ class GenericImporter(TestCase):
self.assertEqual(review.rating, 3.0)
self.assertEqual(review.privacy, "unlisted")
import_item.refresh_from_db()
self.assertEqual(import_item.linked_review.id, review.id)
def test_handle_imported_book_reviews_disabled(self, *_):
"""review import"""
import_job = self.importer.create_job(