Merge pull request #1604 from bookwyrm-social/save-reviews

Associate imported review with import items
This commit is contained in:
Mouse Reeve 2021-11-14 07:02:40 -08:00 committed by GitHub
commit c50e791965
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 1 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

@ -134,8 +134,15 @@
{{ item.normalized_data.shelf }}
</td>
<td>
{% if item.rating %}
<p>{% include 'snippets/stars.html' with rating=item.rating %}</p>
{% endif %}
{% if item.review %}
<p>{{ item.review|truncatechars:100 }}</p>
{% endif %}
{% if item.linked_review %}
<a href="{{ item.linked_review.remote_id }}" target="_blank">{% trans "View imported review" %}</a>
{% endif %}
</td>
{% block import_cols %}
<td>

View file

@ -61,7 +61,7 @@
{% csrf_token %}
<button type="submit" class="button is-danger is-light is-outlined">
<span class="icon icon-x m-0-mobile" aria-hidden="true"></span>
<span class="is-sr-only-mobile">{% trans "Delete" %}</span>
<span class="is-sr-only-mobile">{% trans "Reject" %}</span>
</button>
</form>
</div>

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(