Views various fixes
This commit is contained in:
parent
5af3b95c8d
commit
51415765da
4 changed files with 41 additions and 12 deletions
28
api/views.py
28
api/views.py
|
|
@ -6,7 +6,7 @@ from rest_framework.response import Response
|
|||
from rest_framework.views import APIView
|
||||
from rest_framework.viewsets import ModelViewSet, ViewSet
|
||||
from rest_framework.permissions import IsAuthenticated, AllowAny
|
||||
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
|
||||
from rest_framework.authentication import SessionAuthentication, BasicAuthentication, TokenAuthentication
|
||||
from rest_framework.decorators import api_view, permission_classes, authentication_classes, action
|
||||
from django.utils import timezone
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
|
@ -54,8 +54,13 @@ class PredictionViewSet(ViewSet):
|
|||
except requests.RequestException as e:
|
||||
return Response({"error": f"Tawhiri error: {str(e)}"}, status=status.HTTP_502_BAD_GATEWAY)
|
||||
|
||||
prediction = Prediction.objects.create(
|
||||
result=prediction_result, user=request.user, request=request.data)
|
||||
# prediction = Prediction.objects.create(
|
||||
# result=prediction_result, user=request.user, request=request.data, validated_data=validated_data)
|
||||
prediction = serializer.save(
|
||||
user=request.user,
|
||||
result=prediction_result,
|
||||
request=request.data
|
||||
)
|
||||
|
||||
return Response({
|
||||
"id": prediction.id,
|
||||
|
|
@ -72,7 +77,6 @@ class PredictionViewSet(ViewSet):
|
|||
|
||||
filters = {
|
||||
'user': user,
|
||||
'deleted_at__isnull': True
|
||||
}
|
||||
|
||||
if created_from:
|
||||
|
|
@ -148,7 +152,6 @@ class TelemetryListCreateView(generics.ListCreateAPIView):
|
|||
|
||||
|
||||
class SessionView(APIView):
|
||||
authentication_classes = [SessionAuthentication, BasicAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -157,7 +160,6 @@ class SessionView(APIView):
|
|||
|
||||
|
||||
class WhoAmIView(APIView):
|
||||
authentication_classes = [SessionAuthentication, BasicAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -177,7 +179,7 @@ def get_csrf(request):
|
|||
@extend_schema(methods=["POST"], description="Login user")
|
||||
@csrf_exempt
|
||||
@api_view(["POST"])
|
||||
@authentication_classes([])
|
||||
@authentication_classes([BasicAuthentication])
|
||||
@permission_classes([AllowAny])
|
||||
def login_view(request):
|
||||
data = json.loads(request.body)
|
||||
|
|
@ -207,7 +209,6 @@ def logout_view(request):
|
|||
|
||||
|
||||
class SavedPointViewset(ModelViewSet):
|
||||
authentication_classes = [SessionAuthentication, BasicAuthentication]
|
||||
permission_classes = [IsOwner]
|
||||
serializer_class = SavedPointSerializer
|
||||
pagination_class = None
|
||||
|
|
@ -218,6 +219,17 @@ class SavedPointViewset(ModelViewSet):
|
|||
def perform_create(self, serializer):
|
||||
serializer.save(user=self.request.user)
|
||||
|
||||
class PreditctionTemplateViewset(ModelViewSet):
|
||||
permission_classes = [IsOwner]
|
||||
serializer_class = PreditctionTemplateSerializer
|
||||
pagination_class = None
|
||||
|
||||
def get_queryset(self):
|
||||
return PreditctionTemplate.objects.filter(user=self.request.user)
|
||||
|
||||
def perform_create(self, serializer):
|
||||
serializer.save(user=self.request.user)
|
||||
|
||||
# class PredictionCreateView(APIView):
|
||||
# permission_classes = [IsAuthenticated]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue