diff --git a/bookwyrm/goodreads_import.py b/bookwyrm/goodreads_import.py index 3dcdc2f0..1b2b971c 100644 --- a/bookwyrm/goodreads_import.py +++ b/bookwyrm/goodreads_import.py @@ -4,7 +4,6 @@ import logging from bookwyrm import models from bookwyrm.models import ImportJob, ImportItem -from bookwyrm.status import create_notification from bookwyrm.tasks import app logger = logging.getLogger(__name__) @@ -68,7 +67,6 @@ def import_data(job_id): item.fail_reason = 'Could not find a match for book' item.save() finally: - create_notification(job.user, 'IMPORT', related_import=job) job.complete = True job.save() diff --git a/bookwyrm/models/import_job.py b/bookwyrm/models/import_job.py index b10651b9..af8a35dd 100644 --- a/bookwyrm/models/import_job.py +++ b/bookwyrm/models/import_job.py @@ -2,6 +2,7 @@ import re import dateutil.parser +from django.apps import apps from django.contrib.postgres.fields import JSONField from django.db import models from django.utils import timezone @@ -50,6 +51,19 @@ class ImportJob(models.Model): ) retry = models.BooleanField(default=False) + def save(self, *args, **kwargs): + ''' save and notify ''' + super().save(*args, **kwargs) + if self.complete: + notification_model = apps.get_model( + 'bookwyrm.Notification', require_ready=True) + notification_model.objects.create( + user=self.user, + notification_type='IMPORT', + related_import=self, + ) + + class ImportItem(models.Model): ''' a single line of a csv being imported '''