testingView
This commit is contained in:
1 parent
153a910b6a
commit
6153c02732
2 files changed
+30
No files matched your search
@@ -6,6 +6,7 @@ urlpatterns = [
|
|||||||
path('gettests/', GetTests.as_view(), name="GetTests"),
|
path('gettests/', GetTests.as_view(), name="GetTests"),
|
||||||
path('testdetail/<int:id>/', TestDetail.as_view(),name='TestDetail'),
|
path('testdetail/<int:id>/', TestDetail.as_view(),name='TestDetail'),
|
||||||
path('testcreate/', TestCreate.as_view(),name='TestCreate'),
|
path('testcreate/', TestCreate.as_view(),name='TestCreate'),
|
||||||
|
path('testingview/', TestingView.as_view(), name="TestingView"),
|
||||||
# path('gettesting/', GetTesting.as_view(), name="GetTesting"),
|
# path('gettesting/', GetTesting.as_view(), name="GetTesting"),
|
||||||
path('testresultview/', TestResultView.as_view(), name="TestResultView"),
|
path('testresultview/', TestResultView.as_view(), name="TestResultView"),
|
||||||
]
|
]
|
||||||
@@ -204,6 +204,35 @@ class TestCreate(APIView):
|
|||||||
# test['test_name'] = test_names[test['id']]
|
# test['test_name'] = test_names[test['id']]
|
||||||
# return Response(serializer)
|
# 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):
|
class TestResultView(generics.ListCreateAPIView):
|
||||||
"""API for getting and saving user test results."""
|
"""API for getting and saving user test results."""
|
||||||
queryset = TestResult.objects.all()
|
queryset = TestResult.objects.all()
|
||||||
|
|||||||
Reference in new issue
Block a user