diff --git a/vrobbler/apps/scrobbles/models.py b/vrobbler/apps/scrobbles/models.py index fee4017..4473445 100644 --- a/vrobbler/apps/scrobbles/models.py +++ b/vrobbler/apps/scrobbles/models.py @@ -37,12 +37,6 @@ class AudioScrobblerTSVImport(TimeStampedModel): return f"Audioscrobbler TSV upload: {self.tsv_file.path}" return f"Audioscrobbler TSV upload {self.id}" - def save(self, **kwargs): - """On save, attempt to import the TSV file""" - super().save(**kwargs) - self.process() - return - def process(self, force=False): from scrobbles.tsv import process_audioscrobbler_tsv_file diff --git a/vrobbler/apps/scrobbles/tasks.py b/vrobbler/apps/scrobbles/tasks.py index 88a3769..aebeb6f 100644 --- a/vrobbler/apps/scrobbles/tasks.py +++ b/vrobbler/apps/scrobbles/tasks.py @@ -1,7 +1,7 @@ import logging from celery import shared_task -from scrobbles.models import LastFmImport +from scrobbles.models import AudioScrobblerTSVImport, LastFmImport logger = logging.getLogger(__name__) @@ -13,3 +13,12 @@ def process_lastfm_import(import_id): logger.warn(f"LastFmImport not found with id {import_id}") lastfm_import.process() + + +@shared_task +def process_tsv_import(import_id): + tsv_import = AudioScrobblerTSVImport.objects.filter(id=import_id).first() + if not tsv_import: + logger.warn(f"AudioScrobblerTSVImport not found with id {import_id}") + + tsv_import.process() diff --git a/vrobbler/apps/scrobbles/views.py b/vrobbler/apps/scrobbles/views.py index d40e040..3af4b77 100644 --- a/vrobbler/apps/scrobbles/views.py +++ b/vrobbler/apps/scrobbles/views.py @@ -48,7 +48,7 @@ from scrobbles.serializers import ( AudioScrobblerTSVImportSerializer, ScrobbleSerializer, ) -from scrobbles.tasks import process_lastfm_import +from scrobbles.tasks import process_lastfm_import, process_tsv_import from scrobbles.thesportsdb import lookup_event_from_thesportsdb logger = logging.getLogger(__name__) @@ -173,6 +173,7 @@ class AudioScrobblerImportCreateView( self.object = form.save(commit=False) self.object.user = self.request.user self.object.save() + process_tsv_import.delay(self.object.id) return HttpResponseRedirect(self.get_success_url())