This repository has been archived on 2023-02-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-my-data/mydata/api_views.py
T
Markus Ritberger cf61e0d7da initial commit
2018-06-24 21:16:26 +02:00

29 lines
1.1 KiB
Python

from rest_framework import status
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from mydata.auth import BlenderIdAuthentication
from mydata.blender_opendata import opendata_submit_benchmark
from mydata.serializers import BenchmarkSerializer
"""
API endpoint that allows users to submit benchmarks
"""
class BenchmarkList(APIView):
authentication_classes = (BlenderIdAuthentication,)
permission_classes = (IsAuthenticated,)
def post(self, request, *args, **kwargs):
"""Validates token with Blender ID and sends benchmark to Blender Opendata"""
benchmark_data = opendata_submit_benchmark(request.data, request.user.id)
serializer = BenchmarkSerializer(data=benchmark_data)
if serializer.is_valid():
serializer.save()
return Response(dict(
benchmark_id=serializer.data['benchmark_id'],
manage_id=serializer.data['manage_id']
), status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)