From 1e46de4c9d4a184dedf127a4245fb75254a21b3f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 13 Nov 2021 11:44:05 -0800 Subject: [PATCH 1/3] Associate imported review with import item --- bookwyrm/importers/importer.py | 2 ++ .../0115_importitem_linked_review.py | 24 +++++++++++++++++++ bookwyrm/models/import_job.py | 3 +++ bookwyrm/tests/importers/test_importer.py | 6 +++++ 4 files changed, 35 insertions(+) create mode 100644 bookwyrm/migrations/0115_importitem_linked_review.py diff --git a/bookwyrm/importers/importer.py b/bookwyrm/importers/importer.py index 71f02231..a1c35ef7 100644 --- a/bookwyrm/importers/importer.py +++ b/bookwyrm/importers/importer.py @@ -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() diff --git a/bookwyrm/migrations/0115_importitem_linked_review.py b/bookwyrm/migrations/0115_importitem_linked_review.py new file mode 100644 index 00000000..8cff9b8c --- /dev/null +++ b/bookwyrm/migrations/0115_importitem_linked_review.py @@ -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", + ), + ), + ] diff --git a/bookwyrm/models/import_job.py b/bookwyrm/models/import_job.py index 6b8f0b46..ddd9eaec 100644 --- a/bookwyrm/models/import_job.py +++ b/bookwyrm/models/import_job.py @@ -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""" diff --git a/bookwyrm/tests/importers/test_importer.py b/bookwyrm/tests/importers/test_importer.py index 45d87171..99cdcd28 100644 --- a/bookwyrm/tests/importers/test_importer.py +++ b/bookwyrm/tests/importers/test_importer.py @@ -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( From 712d8ecfb437fcafafbfc971e796b8b01895c72b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 13 Nov 2021 11:52:08 -0800 Subject: [PATCH 2/3] Don't show empty stars when there's no review --- bookwyrm/templates/import/import_status.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bookwyrm/templates/import/import_status.html b/bookwyrm/templates/import/import_status.html index f5f590e1..4871a4c7 100644 --- a/bookwyrm/templates/import/import_status.html +++ b/bookwyrm/templates/import/import_status.html @@ -134,8 +134,15 @@ {{ item.normalized_data.shelf }} + {% if item.rating %}

{% include 'snippets/stars.html' with rating=item.rating %}

+ {% endif %} + {% if item.review %}

{{ item.review|truncatechars:100 }}

+ {% endif %} + {% if item.linked_review %} + {% trans "View imported review" %} + {% endif %} {% block import_cols %} From 8b7720c8b85264e533bc160991f36e533ed46461 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 13 Nov 2021 11:54:28 -0800 Subject: [PATCH 3/3] Use "reject" instead of "delete" on review page --- bookwyrm/templates/import/manual_review.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templates/import/manual_review.html b/bookwyrm/templates/import/manual_review.html index 2c487563..b6c2b6b2 100644 --- a/bookwyrm/templates/import/manual_review.html +++ b/bookwyrm/templates/import/manual_review.html @@ -61,7 +61,7 @@ {% csrf_token %}