mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-28 03:23:45 +03:00
updated last fm scrobling
This commit is contained in:
parent
9dd23e1a01
commit
f6e2d1fe4b
|
@ -86,6 +86,11 @@ def album_name(self):
|
||||||
def artists_names(self):
|
def artists_names(self):
|
||||||
return cache_model_property(self, "_authors_names")
|
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):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
|
@ -211,7 +211,7 @@ def listen_to_song(song_id, user_id=None, anon=True):
|
||||||
session_key=lastfm_token,
|
session_key=lastfm_token,
|
||||||
)
|
)
|
||||||
song = Song.objects.get(id=song_id)
|
song = Song.objects.get(id=song_id)
|
||||||
artist_name = song.artists_names
|
artist_name = song.get_first_author_name()
|
||||||
track_name = song.name
|
track_name = song.name
|
||||||
album_name = song.album.name
|
album_name = song.album.name
|
||||||
timestamp = int(timezone.now().timestamp())
|
timestamp = int(timezone.now().timestamp())
|
||||||
|
|
|
@ -214,23 +214,16 @@ def list_tokens(request):
|
||||||
@login_required
|
@login_required
|
||||||
def create_token(request):
|
def create_token(request):
|
||||||
initial_data = {}
|
initial_data = {}
|
||||||
|
|
||||||
# Обработка параметров 'name' и 'active_until'
|
|
||||||
if "name" in request.GET:
|
if "name" in request.GET:
|
||||||
initial_data["name"] = request.GET["name"]
|
initial_data["name"] = request.GET["name"]
|
||||||
if "active_until" in request.GET:
|
if "active_until" in request.GET:
|
||||||
initial_data["active_until"] = request.GET["active_until"]
|
initial_data["active_until"] = request.GET["active_until"]
|
||||||
|
|
||||||
# Создаем QueryDict для разрешений, чтобы правильно обработать повторяющиеся ключи
|
|
||||||
permissions_query_dict = QueryDict("", mutable=True)
|
permissions_query_dict = QueryDict("", mutable=True)
|
||||||
|
|
||||||
# Разбор параметров разрешений
|
|
||||||
permissions = request.GET.getlist("permissions")
|
permissions = request.GET.getlist("permissions")
|
||||||
for perm in permissions:
|
for perm in permissions:
|
||||||
category, permission = perm.split(".")
|
category, permission = perm.split(".")
|
||||||
permissions_query_dict.update({f"permissions_{category}": [permission]})
|
permissions_query_dict.update({f"permissions_{category}": [permission]})
|
||||||
|
|
||||||
# Переводим QueryDict в обычный словарь для использования в initial
|
|
||||||
permissions_data = {key: value for key, value in permissions_query_dict.lists()}
|
permissions_data = {key: value for key, value in permissions_query_dict.lists()}
|
||||||
|
|
||||||
initial_data.update(permissions_data)
|
initial_data.update(permissions_data)
|
||||||
|
@ -242,7 +235,6 @@ def create_token(request):
|
||||||
initial=initial_data, permissions_context=UserAPIToken.permission_template
|
initial=initial_data, permissions_context=UserAPIToken.permission_template
|
||||||
)
|
)
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
print(request.POST)
|
|
||||||
form = TokenCreationForm(request.POST)
|
form = TokenCreationForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
new_token = form.save(commit=False)
|
new_token = form.save(commit=False)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user