testingView

This commit is contained in:
cja committed 2025-05-19 10:46:27 +03:00
1 parent 153a910b6a
commit 6153c02732
2 files changed
+30

No files matched your search

+1
View File
@@ -6,6 +6,7 @@ urlpatterns = [
path('gettests/', GetTests.as_view(), name="GetTests"),
path('testdetail/<int:id>/', TestDetail.as_view(),name='TestDetail'),
path('testcreate/', TestCreate.as_view(),name='TestCreate'),
path('testingview/', TestingView.as_view(), name="TestingView"),
# path('gettesting/', GetTesting.as_view(), name="GetTesting"),
path('testresultview/', TestResultView.as_view(), name="TestResultView"),
]
+29
View File
@@ -204,6 +204,35 @@ class TestCreate(APIView):
# test['test_name'] = test_names[test['id']]
# return Response(serializer)
class TestingView(generics.ListCreateAPIView):
"""API for testing."""
queryset = Testing.objects.all()
serializer_class = TestingSeriaizer
pagination_class = None
def post(self, request):
"""create testing"""
try:
testing = Testing.objects.create(
user=User.objects.get(request.data["user_id"]),
test=Test.objects.get(request.data["test_id"]),
completion_date=request.data["completion_date"],
test_passed=False,
)
return Response(
{"status": "success", "message": "Testing created successfully."},
status=200,
)
except ValueError as e:
return Response({"status": "error", "message": str(e)}, status=400)
except DatabaseError as e:
print(e)
return Response({"status": "error", "message": str(e)}, status=400)
class TestResultView(generics.ListCreateAPIView):
"""API for getting and saving user test results."""
queryset = TestResult.objects.all()