provide DRF action to run a pi simulation
This commit is contained in:
parent
ef08cec0fb
commit
da815a1fc3
14
pi/views.py
14
pi/views.py
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user