diff --git a/bookwyrm/importers/importer.py b/bookwyrm/importers/importer.py index 05550429b..438ff7dbb 100644 --- a/bookwyrm/importers/importer.py +++ b/bookwyrm/importers/importer.py @@ -126,6 +126,7 @@ def import_item_task(item_id): except Exception as err: # pylint: disable=broad-except item.fail_reason = _("Error loading book") item.save() + item.update_job() raise err if item.book: @@ -135,6 +136,7 @@ def import_item_task(item_id): item.fail_reason = _("Could not find a match for book") item.save() + item.update_job() def handle_imported_book(item): @@ -144,6 +146,8 @@ def handle_imported_book(item): if isinstance(item.book, models.Work): item.book = item.book.default_edition if not item.book: + item.fail_reason = _("Error loading book") + item.save() return if not isinstance(item.book, models.Edition): item.book = item.book.edition diff --git a/bookwyrm/migrations/0116_auto_20211114_1700.py b/bookwyrm/migrations/0116_auto_20211114_1700.py new file mode 100644 index 000000000..ff71b89ce --- /dev/null +++ b/bookwyrm/migrations/0116_auto_20211114_1700.py @@ -0,0 +1,32 @@ +# Generated by Django 3.2.5 on 2021-11-14 17:00 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0115_importitem_linked_review'), + ] + + operations = [ + migrations.RemoveField( + model_name='importjob', + name='complete', + ), + migrations.RemoveField( + model_name='importjob', + name='task_id', + ), + migrations.AddField( + model_name='importjob', + name='completed_count', + field=models.IntegerField(default=0), + ), + migrations.AddField( + model_name='importjob', + name='updated_date', + field=models.DateTimeField(default=django.utils.timezone.now), + ), + ] diff --git a/bookwyrm/models/import_job.py b/bookwyrm/models/import_job.py index 753662d65..953ae3946 100644 --- a/bookwyrm/models/import_job.py +++ b/bookwyrm/models/import_job.py @@ -35,10 +35,10 @@ class ImportJob(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) created_date = models.DateTimeField(default=timezone.now) - task_id = models.CharField(max_length=100, null=True) # TODO: deprecated include_reviews = models.BooleanField(default=True) mappings = models.JSONField() - complete = models.BooleanField(default=False) + updated_date = models.DateTimeField(default=timezone.now) + completed_count = models.IntegerField(default=0) source = models.CharField(max_length=100) privacy = models.CharField( max_length=255, default="public", choices=PrivacyLevels.choices @@ -66,6 +66,12 @@ class ImportItem(models.Model): "Review", on_delete=models.SET_NULL, null=True, blank=True ) + def update_job(self): + """this user is here! they are doing things!""" + self.job.completed_count += 1 + self.job.updated_date = timezone.now() + self.job.save() + def resolve(self): """try various ways to lookup a book""" # we might be calling this after manually adding the book,