From 8042c726b04474b81d473de37aa7bc8de36df7b4 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Thu, 6 Apr 2023 13:37:10 -0400 Subject: [PATCH] Allow profile disable of lastfm imports --- .../0008_userprofile_lastfm_auto_import.py | 18 ++++++++++++++++++ vrobbler/apps/profiles/models.py | 1 + vrobbler/apps/scrobbles/utils.py | 4 +++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 vrobbler/apps/profiles/migrations/0008_userprofile_lastfm_auto_import.py diff --git a/vrobbler/apps/profiles/migrations/0008_userprofile_lastfm_auto_import.py b/vrobbler/apps/profiles/migrations/0008_userprofile_lastfm_auto_import.py new file mode 100644 index 0000000..30ef849 --- /dev/null +++ b/vrobbler/apps/profiles/migrations/0008_userprofile_lastfm_auto_import.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.7 on 2023-04-06 17:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("profiles", "0007_alter_userprofile_timezone"), + ] + + operations = [ + migrations.AddField( + model_name="userprofile", + name="lastfm_auto_import", + field=models.BooleanField(default=False), + ), + ] diff --git a/vrobbler/apps/profiles/models.py b/vrobbler/apps/profiles/models.py index f88f08d..1c56463 100644 --- a/vrobbler/apps/profiles/models.py +++ b/vrobbler/apps/profiles/models.py @@ -23,6 +23,7 @@ class UserProfile(TimeStampedModel): ) lastfm_username = models.CharField(max_length=255, **BNULL) lastfm_password = EncryptedField(**BNULL) + lastfm_auto_import = models.BooleanField(default=False) def __str__(self): return f"User profile for {self.user}" diff --git a/vrobbler/apps/scrobbles/utils.py b/vrobbler/apps/scrobbles/utils.py index fa976fc..2a6034e 100644 --- a/vrobbler/apps/scrobbles/utils.py +++ b/vrobbler/apps/scrobbles/utils.py @@ -197,7 +197,9 @@ def import_lastfm_for_all_users(): """Grab a list of all users with LastFM enabled and kickoff imports for them""" LastFmImport = apps.get_model("scrobbles", "LastFMImport") lastfm_enabled_user_ids = UserProfile.objects.filter( - lastfm_username__isnull=False, lastfm_password__isnull=False + lastfm_username__isnull=False, + lastfm_password__isnull=False, + lastfm_auto_import=True, ).values_list("user_id", flat=True) for user_id in lastfm_enabled_user_ids: