timelaps-api/music/decorators.py
2019-04-18 00:58:59 +02:00

19 lines
615 B
Python

from rest_framework.response import Response
from rest_framework.views import status
def validate_request_data(fn):
def decorated(*args, **kwargs):
# args[0] == GenericView Object
title = args[0].request.data.get("title", "")
artist = args[0].request.data.get("artist", "")
if not title and not artist:
return Response(
data={
"message": "Both title and artist are required to add a song"
},
status=status.HTTP_400_BAD_REQUEST
)
return fn(*args, **kwargs)
return decorated