From 106d442a0bc88d1faec9841d23193fde339a486b Mon Sep 17 00:00:00 2001
From: Mouse Reeve <mousereeve@riseup.net>
Date: Wed, 10 Feb 2021 14:18:55 -0800
Subject: [PATCH] Moves import complete notification to model

---
 bookwyrm/goodreads_import.py  |  2 --
 bookwyrm/models/import_job.py | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/bookwyrm/goodreads_import.py b/bookwyrm/goodreads_import.py
index 3dcdc2f09..1b2b971c7 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 b10651b96..af8a35ddf 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 '''