mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-10 09:12:23 +01:00
Marietje 4.1: Addition of Django REST framework, Swagger, Dark mode and updates to Django and Bootstrap
This commit is contained in:
@ -2,4 +2,4 @@ from django.apps import AppConfig
|
||||
|
||||
|
||||
class PlayerapiConfig(AppConfig):
|
||||
name = 'playerapi'
|
||||
name = "playerapi"
|
||||
|
||||
@ -7,8 +7,8 @@ from queues.models import Queue
|
||||
|
||||
def token_required(function):
|
||||
def _dec(request):
|
||||
queue = get_object_or_404(Queue, id=request.POST.get('queue'))
|
||||
if not check_password(request.POST.get('player_token'), queue.player_token):
|
||||
queue = get_object_or_404(Queue, id=request.POST.get("queue"))
|
||||
if not check_password(request.POST.get("player_token"), queue.player_token):
|
||||
return HttpResponseForbidden()
|
||||
return function(request)
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
from django.conf.urls import url
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
app_name = 'playerapi'
|
||||
app_name = "playerapi"
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^queue', views.queue),
|
||||
url(r'^play', views.play),
|
||||
url(r'^next', views.next),
|
||||
url(r'^analysed', views.analysed),
|
||||
path("queue/", views.queue),
|
||||
path("play/", views.play),
|
||||
path("next/", views.next),
|
||||
path("analysed/", views.analysed),
|
||||
]
|
||||
|
||||
@ -14,22 +14,30 @@ from .decorators import token_required
|
||||
@csrf_exempt
|
||||
@token_required
|
||||
def queue(request):
|
||||
current_queue = get_object_or_404(Queue, id=request.POST.get('queue'))
|
||||
current_queue = get_object_or_404(Queue, id=request.POST.get("queue"))
|
||||
commands = current_queue.queuecommand_set.all()
|
||||
response = JsonResponse({
|
||||
'current_song': playlist_song_to_dict(current_queue.current_song(), include_hash=True, include_replaygain=True),
|
||||
'queue': [playlist_song_to_dict(playlist_song, include_hash=True, include_replaygain=True) for playlist_song in current_queue.queue()[:1]],
|
||||
'commands': [command.command for command in commands]
|
||||
})
|
||||
response = JsonResponse(
|
||||
{
|
||||
"current_song": playlist_song_to_dict(
|
||||
current_queue.current_song(), include_hash=True, include_replaygain=True
|
||||
),
|
||||
"queue": [
|
||||
playlist_song_to_dict(playlist_song, include_hash=True, include_replaygain=True)
|
||||
for playlist_song in current_queue.queue()[:1]
|
||||
],
|
||||
"commands": [command.command for command in commands],
|
||||
}
|
||||
)
|
||||
for command in commands:
|
||||
command.delete()
|
||||
|
||||
return response
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@token_required
|
||||
def play(request):
|
||||
current_queue = get_object_or_404(Queue, id=request.POST.get('queue'))
|
||||
current_queue = get_object_or_404(Queue, id=request.POST.get("queue"))
|
||||
current_queue.started_at = timezone.now()
|
||||
current_queue.save()
|
||||
current_song = current_queue.current_song()
|
||||
@ -43,7 +51,7 @@ def play(request):
|
||||
@csrf_exempt
|
||||
@token_required
|
||||
def next(request):
|
||||
current_queue = get_object_or_404(Queue, id=request.POST.get('queue'))
|
||||
current_queue = get_object_or_404(Queue, id=request.POST.get("queue"))
|
||||
player_song = current_queue.current_song()
|
||||
player_song.state = 2
|
||||
player_song.save()
|
||||
@ -53,10 +61,10 @@ def next(request):
|
||||
@csrf_exempt
|
||||
@token_required
|
||||
def analysed(request):
|
||||
song = get_object_or_404(Song, id=request.POST.get('song'))
|
||||
if 'gain' in request.POST:
|
||||
song.rg_gain = request.POST.get('gain')
|
||||
if 'peak' in request.POST:
|
||||
song.rg_peak = request.POST.get('peak')
|
||||
song = get_object_or_404(Song, id=request.POST.get("song"))
|
||||
if "gain" in request.POST:
|
||||
song.rg_gain = request.POST.get("gain")
|
||||
if "peak" in request.POST:
|
||||
song.rg_peak = request.POST.get("peak")
|
||||
song.save()
|
||||
return JsonResponse({})
|
||||
|
||||
Reference in New Issue
Block a user