save playlist only when data is different
This commit is contained in:
parent
21ca4b7d11
commit
40a26176eb
@ -14,6 +14,8 @@ import zmq
|
||||
from apps.api_player.models import GuiSettings
|
||||
from django.conf import settings
|
||||
from natsort import natsorted
|
||||
from rest_framework import status
|
||||
from rest_framework.response import Response
|
||||
|
||||
|
||||
def read_yaml():
|
||||
@ -53,9 +55,20 @@ def write_json(data):
|
||||
os.makedirs(_path, exist_ok=True)
|
||||
|
||||
output = os.path.join(_path, '{}.json'.format(data['date']))
|
||||
|
||||
if os.path.isfile(output) and data == read_json(data['date']):
|
||||
return Response({
|
||||
'text': 'Playlist from {} already exists'.format(data['date'])
|
||||
}, status.HTTP_204_NO_CONTENT)
|
||||
|
||||
|
||||
with open(output, "w") as outfile:
|
||||
json.dump(data, outfile, indent=4)
|
||||
|
||||
return Response({
|
||||
'text': 'Playlist from {} saved'.format(data['date'])
|
||||
}, status.HTTP_201_CREATED)
|
||||
|
||||
|
||||
def read_log(type, _date):
|
||||
config = read_yaml()
|
||||
|
@ -7,7 +7,7 @@ from apps.api_player.serializers import (GuiSettingsSerializer,
|
||||
MessengerSerializer, UserSerializer)
|
||||
from django.contrib.auth.models import User
|
||||
from django_filters import rest_framework as filters
|
||||
from rest_framework import viewsets
|
||||
from rest_framework import status, viewsets
|
||||
from rest_framework.parsers import FileUploadParser, JSONParser
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
@ -169,10 +169,11 @@ class Playlist(APIView):
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
if 'data' in request.data:
|
||||
write_json(request.data['data'])
|
||||
return Response(status=200)
|
||||
_respose = write_json(request.data['data'])
|
||||
return _respose
|
||||
|
||||
return Response(status=400)
|
||||
return Response({'text': 'Unspecified save error'},
|
||||
status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
class Statistics(APIView):
|
||||
|
Loading…
Reference in New Issue
Block a user