Moves import complete notification to model

This commit is contained in:
Mouse Reeve 2021-02-10 14:18:55 -08:00
parent ca08bfa6f5
commit 106d442a0b
2 changed files with 14 additions and 2 deletions

View file

@ -4,7 +4,6 @@ import logging
from bookwyrm import models from bookwyrm import models
from bookwyrm.models import ImportJob, ImportItem from bookwyrm.models import ImportJob, ImportItem
from bookwyrm.status import create_notification
from bookwyrm.tasks import app from bookwyrm.tasks import app
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -68,7 +67,6 @@ def import_data(job_id):
item.fail_reason = 'Could not find a match for book' item.fail_reason = 'Could not find a match for book'
item.save() item.save()
finally: finally:
create_notification(job.user, 'IMPORT', related_import=job)
job.complete = True job.complete = True
job.save() job.save()

View file

@ -2,6 +2,7 @@
import re import re
import dateutil.parser import dateutil.parser
from django.apps import apps
from django.contrib.postgres.fields import JSONField from django.contrib.postgres.fields import JSONField
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
@ -50,6 +51,19 @@ class ImportJob(models.Model):
) )
retry = models.BooleanField(default=False) 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): class ImportItem(models.Model):
''' a single line of a csv being imported ''' ''' a single line of a csv being imported '''