From 6301656a0ec2367a4450c4ab8da57f4136c23c0f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 10 Aug 2021 13:46:20 -0700 Subject: [PATCH 1/6] Fixes setting book results from title/author search --- bookwyrm/models/import_job.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bookwyrm/models/import_job.py b/bookwyrm/models/import_job.py index f29938469..81c75b4b2 100644 --- a/bookwyrm/models/import_job.py +++ b/bookwyrm/models/import_job.py @@ -71,6 +71,7 @@ class ImportItem(models.Model): index = models.IntegerField() data = models.JSONField() book = models.ForeignKey(Book, on_delete=models.SET_NULL, null=True, blank=True) + book_guess = models.ForeignKey(Book, on_delete=models.SET_NULL, null=True, blank=True) fail_reason = models.TextField(null=True) def resolve(self): @@ -80,7 +81,7 @@ class ImportItem(models.Model): else: # don't fall back on title/author search is isbn is present. # you're too likely to mismatch - self.get_book_from_title_author() + self.book = self.get_book_from_title_author() def get_book_from_isbn(self): """search by isbn""" From ebabbf475a0496861d7a8858627ffa4a6ab82f2c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 10 Aug 2021 13:48:09 -0700 Subject: [PATCH 2/6] Translate error messages --- bookwyrm/importers/importer.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bookwyrm/importers/importer.py b/bookwyrm/importers/importer.py index d5f1449ca..48629a01f 100644 --- a/bookwyrm/importers/importer.py +++ b/bookwyrm/importers/importer.py @@ -3,6 +3,7 @@ import csv import logging from django.utils import timezone +from django.utils.translation import gettext_lazy as _ from bookwyrm import models from bookwyrm.models import ImportJob, ImportItem @@ -71,7 +72,7 @@ def import_data(source, job_id): item.resolve() except Exception as err: # pylint: disable=broad-except logger.exception(err) - item.fail_reason = "Error loading book" + item.fail_reason = _("Error loading book") item.save() continue @@ -83,7 +84,7 @@ def import_data(source, job_id): source, job.user, item, job.include_reviews, job.privacy ) else: - item.fail_reason = "Could not find a match for book" + item.fail_reason = _("Could not find a match for book") item.save() finally: job.complete = True From fa396d4bc8c3419497eeeb9246b583aa33c2e420 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 10 Aug 2021 13:54:52 -0700 Subject: [PATCH 3/6] Save best-guess search results on import --- bookwyrm/importers/importer.py | 3 ++- .../migrations/0083_importitem_book_guess.py | 25 +++++++++++++++++++ bookwyrm/models/import_job.py | 18 ++++++++++--- 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 bookwyrm/migrations/0083_importitem_book_guess.py diff --git a/bookwyrm/importers/importer.py b/bookwyrm/importers/importer.py index 48629a01f..39d88e100 100644 --- a/bookwyrm/importers/importer.py +++ b/bookwyrm/importers/importer.py @@ -76,9 +76,10 @@ def import_data(source, job_id): item.save() continue - if item.book: + if item.book or item.book_guess: item.save() + if item.book: # shelves book and handles reviews handle_imported_book( source, job.user, item, job.include_reviews, job.privacy diff --git a/bookwyrm/migrations/0083_importitem_book_guess.py b/bookwyrm/migrations/0083_importitem_book_guess.py new file mode 100644 index 000000000..fa4f94ab3 --- /dev/null +++ b/bookwyrm/migrations/0083_importitem_book_guess.py @@ -0,0 +1,25 @@ +# Generated by Django 3.2.4 on 2021-08-10 20:49 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0082_auto_20210806_2324"), + ] + + operations = [ + migrations.AddField( + model_name="importitem", + name="book_guess", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="book_guess", + to="bookwyrm.book", + ), + ), + ] diff --git a/bookwyrm/models/import_job.py b/bookwyrm/models/import_job.py index 81c75b4b2..53368bce2 100644 --- a/bookwyrm/models/import_job.py +++ b/bookwyrm/models/import_job.py @@ -71,7 +71,13 @@ class ImportItem(models.Model): index = models.IntegerField() data = models.JSONField() book = models.ForeignKey(Book, on_delete=models.SET_NULL, null=True, blank=True) - book_guess = models.ForeignKey(Book, on_delete=models.SET_NULL, null=True, blank=True) + book_guess = models.ForeignKey( + Book, + on_delete=models.SET_NULL, + null=True, + blank=True, + related_name="book_guess", + ) fail_reason = models.TextField(null=True) def resolve(self): @@ -81,7 +87,11 @@ class ImportItem(models.Model): else: # don't fall back on title/author search is isbn is present. # you're too likely to mismatch - self.book = self.get_book_from_title_author() + book, confidence = self.get_book_from_title_author() + if confidence > 0.999: + self.book = book + else: + self.book_guess = book def get_book_from_isbn(self): """search by isbn""" @@ -97,12 +107,12 @@ class ImportItem(models.Model): """search by title and author""" search_term = construct_search_term(self.title, self.author) search_result = connector_manager.first_search_result( - search_term, min_confidence=0.999 + search_term, min_confidence=0.1 ) if search_result: # raises ConnectorException return search_result.connector.get_or_create_book(search_result.key) - return None + return None, 0 @property def title(self): From ef1896da18b78f53b388cb9cd5df12c57b204bb0 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 10 Aug 2021 14:02:22 -0700 Subject: [PATCH 4/6] Return confidence rating --- bookwyrm/models/import_job.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bookwyrm/models/import_job.py b/bookwyrm/models/import_job.py index 53368bce2..53192ce37 100644 --- a/bookwyrm/models/import_job.py +++ b/bookwyrm/models/import_job.py @@ -85,7 +85,7 @@ class ImportItem(models.Model): if self.isbn: self.book = self.get_book_from_isbn() else: - # don't fall back on title/author search is isbn is present. + # don't fall back on title/author search if isbn is present. # you're too likely to mismatch book, confidence = self.get_book_from_title_author() if confidence > 0.999: @@ -111,7 +111,10 @@ class ImportItem(models.Model): ) if search_result: # raises ConnectorException - return search_result.connector.get_or_create_book(search_result.key) + return ( + search_result.connector.get_or_create_book(search_result.key), + search_result.confidence, + ) return None, 0 @property From 255e59503b8c4a5cfdff372674e3db7612765694 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 11 Sep 2021 07:23:22 -0700 Subject: [PATCH 5/6] Updates migration --- ...importitem_book_guess.py => 0094_importitem_book_guess.py} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename bookwyrm/migrations/{0083_importitem_book_guess.py => 0094_importitem_book_guess.py} (80%) diff --git a/bookwyrm/migrations/0083_importitem_book_guess.py b/bookwyrm/migrations/0094_importitem_book_guess.py similarity index 80% rename from bookwyrm/migrations/0083_importitem_book_guess.py rename to bookwyrm/migrations/0094_importitem_book_guess.py index fa4f94ab3..be703cdde 100644 --- a/bookwyrm/migrations/0083_importitem_book_guess.py +++ b/bookwyrm/migrations/0094_importitem_book_guess.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.4 on 2021-08-10 20:49 +# Generated by Django 3.2.4 on 2021-09-11 14:22 from django.db import migrations, models import django.db.models.deletion @@ -7,7 +7,7 @@ import django.db.models.deletion class Migration(migrations.Migration): dependencies = [ - ("bookwyrm", "0082_auto_20210806_2324"), + ("bookwyrm", "0093_alter_sitesettings_instance_short_description"), ] operations = [ From d31683e21fa500fd7ee2b274696e09ac0025a30d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 11 Sep 2021 14:43:36 -0700 Subject: [PATCH 6/6] Adds merge migration --- bookwyrm/migrations/0095_merge_20210911_2143.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 bookwyrm/migrations/0095_merge_20210911_2143.py diff --git a/bookwyrm/migrations/0095_merge_20210911_2143.py b/bookwyrm/migrations/0095_merge_20210911_2143.py new file mode 100644 index 000000000..ea6b5a346 --- /dev/null +++ b/bookwyrm/migrations/0095_merge_20210911_2143.py @@ -0,0 +1,13 @@ +# Generated by Django 3.2.4 on 2021-09-11 21:43 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0094_auto_20210911_1550"), + ("bookwyrm", "0094_importitem_book_guess"), + ] + + operations = []