Page MenuHome

api_views.py
No OneTemporary

File Metadata

Created
Fri, Dec 6, 1:52 PM

api_views.py

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.blender_opendata import opendata_submit_benchmark
from mydata.oauth.blender import BlenderIdToken
from mydata.serializers import BenchmarkSerializer
class BenchmarkSubmit(APIView):
"""
API endpoint that allows users to submit benchmarks
"""
authentication_classes = (BlenderIdToken,)
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.blender_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)

Event Timeline