Merge where I left backend-frameworkification #2

Manually merged
bss merged 18 commits from backend-frameworkification into master 2021-04-24 15:36:23 -05:00
1 changed files with 12 additions and 2 deletions
Showing only changes of commit da815a1fc3 - Show all commits

View File

@ -1,12 +1,22 @@
"""Provide pi simulation results."""
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import ReadOnlyModelViewSet
from pi.models import PiLog
from pi.serializers import PiLogSerializer
class PiLogViewSet(viewsets.ReadOnlyModelViewSet):
class PiLogViewSet(ReadOnlyModelViewSet):
"""Provide list and detail actions for pi simulation log entries."""
queryset = PiLog.objects.all()
serializer_class = PiLogSerializer
permission_classes = [IsAuthenticated]
@action(detail=False, methods=['post'])
def simulate(self, request):
"""Run one simulation of the pi estimator."""
simulation, _, _ = PiLog.objects.simulate()
return Response(self.get_serializer(simulation).data)