From f6e2d1fe4b29aac2f0538bfcef58ce4651f742be Mon Sep 17 00:00:00 2001 From: Alexander-D-Karpov Date: Wed, 10 Apr 2024 17:15:41 +0300 Subject: [PATCH] updated last fm scrobling --- akarpov/music/models.py | 5 +++++ akarpov/music/tasks.py | 2 +- akarpov/users/views.py | 8 -------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/akarpov/music/models.py b/akarpov/music/models.py index 418c7d9..883f4f4 100644 --- a/akarpov/music/models.py +++ b/akarpov/music/models.py @@ -86,6 +86,11 @@ def album_name(self): def artists_names(self): return cache_model_property(self, "_authors_names") + def get_first_author_name(self): + if self.authors: + return self.authors.first().name + return "" + def __str__(self): return self.name diff --git a/akarpov/music/tasks.py b/akarpov/music/tasks.py index bb6e0bf..1e0203c 100644 --- a/akarpov/music/tasks.py +++ b/akarpov/music/tasks.py @@ -211,7 +211,7 @@ def listen_to_song(song_id, user_id=None, anon=True): session_key=lastfm_token, ) song = Song.objects.get(id=song_id) - artist_name = song.artists_names + artist_name = song.get_first_author_name() track_name = song.name album_name = song.album.name timestamp = int(timezone.now().timestamp()) diff --git a/akarpov/users/views.py b/akarpov/users/views.py index 4b17749..9e0f1f0 100644 --- a/akarpov/users/views.py +++ b/akarpov/users/views.py @@ -214,23 +214,16 @@ def list_tokens(request): @login_required def create_token(request): initial_data = {} - - # Обработка параметров 'name' и 'active_until' if "name" in request.GET: initial_data["name"] = request.GET["name"] if "active_until" in request.GET: initial_data["active_until"] = request.GET["active_until"] - # Создаем QueryDict для разрешений, чтобы правильно обработать повторяющиеся ключи permissions_query_dict = QueryDict("", mutable=True) - - # Разбор параметров разрешений permissions = request.GET.getlist("permissions") for perm in permissions: category, permission = perm.split(".") permissions_query_dict.update({f"permissions_{category}": [permission]}) - - # Переводим QueryDict в обычный словарь для использования в initial permissions_data = {key: value for key, value in permissions_query_dict.lists()} initial_data.update(permissions_data) @@ -242,7 +235,6 @@ def create_token(request): initial=initial_data, permissions_context=UserAPIToken.permission_template ) if request.method == "POST": - print(request.POST) form = TokenCreationForm(request.POST) if form.is_valid(): new_token = form.save(commit=False)