29 lines
1.1 KiB
Python
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) |