chore [P-01]: подтянул бэк

This commit is contained in:
Denis Voinovich committed 2025-06-04 13:16:58 +03:00
commit 40793f55e9
1 file changed
+13 -18
+13 -18
View File
@@ -51,7 +51,7 @@ class GetTests(generics.ListAPIView):
400: 'error',
}
)
def get (self, request, *args, **kwargs):
def get (self, request):
"""receives tests assigned to the user"""
user = request.user
# user = User.objects.get(username='9966-00-125')
@@ -100,6 +100,7 @@ class GetTests(generics.ListAPIView):
test.attemps_number = test.attemps_number - attempt_counts.get(test.id, 0)
def delete(self, request):
"""makes the test not available"""
test_id = request.data.get("test_id")
try:
@@ -123,7 +124,7 @@ class TestDetail(generics.RetrieveUpdateDestroyAPIView):
lookup_url_kwarg = 'id'
lookup_field = 'id'
def get(self, request, *args, **kwargs):
def get(self):
"""Processes a GET request to retrieve detailed information about a test."""
test = self.get_object()
number_of_questions = test.question_count
@@ -143,7 +144,7 @@ class TestCreate(APIView):
create test
"""
try:
test = self.create_test(request)
self.create_test(request)
return Response(
{"status": "success", "message": "Test created successfully."},
@@ -215,8 +216,6 @@ class TestCreate(APIView):
right_wrong=answer["right_wrong"],
)
return test
# class GetTesting(APIView):
# def get(self, request):
@@ -254,7 +253,6 @@ class TestingView(generics.ListCreateAPIView):
)
def get(self, request):
"""Get all testing records for a test"""
user = request.user
test_id = request.query_params.get('test_id')
try:
if test_id:
@@ -323,6 +321,7 @@ class TestingView(generics.ListCreateAPIView):
return Response({"status": "error", "message": str(e)}, status=400)
def delete(self, request):
"""delete testing"""
testing_id = request.data.get("id")
try:
testing = Testing.objects.get(id=testing_id)
@@ -369,6 +368,7 @@ class TestingView(generics.ListCreateAPIView):
testing.save()
def change_news(self, testing):
"""change news if the test assignment for an employee has been removed"""
if not testing.news:
return
user_fio = testing.user.user.fio
@@ -405,7 +405,7 @@ class TestResultView(generics.ListCreateAPIView):
400: 'error',
}
)
def get(self, request, *args, **kwargs):
def get(self, request):
"""Get the results of the last user test attempt."""
user = request.user
# user = User.objects.get(username = "9966-00-125")
@@ -448,7 +448,7 @@ class TestResultView(generics.ListCreateAPIView):
400: 'error',
}
)
def post(self, request, *args, **kwargs):
def post(self, request):
"""Saves the results of a new test attempt."""
try:
user = request.user
@@ -477,7 +477,6 @@ class TestResultView(generics.ListCreateAPIView):
'answer': None,
})
# answer_ids = [item['answer'] for item in request.data]
test_info = self.get_test_info(answer_ids, test_id)
if status == 'testing':
test_attempt, testing = self.create_test_attempt(user, test_info)
@@ -486,12 +485,12 @@ class TestResultView(generics.ListCreateAPIView):
serializer = self.get_serializer(data=prepared_data, many=True)
if serializer.is_valid():
serializer.save(attempt=test_attempt)
self.update_testing(user, test_info, testing)
self.update_testing(test_info, testing)
return Response(data={'score': test_info['score'],
'answered_questions_total': test_info['answered_questions_total'],
'is_passed': test_info['is_passed']})
except Exception as e:
except Exception as e: #pylint: disable=W0718
print(e)
return Response({"status": "error", "message": str(e)}, status=400)
@@ -507,15 +506,11 @@ class TestResultView(generics.ListCreateAPIView):
completion_date= datetime.now())
return test_attempt, testing
def update_testing(self, user, test_info, testing):
def update_testing(self, test_info, testing):
"""Updates or creates a Testing record with a test passing flag."""
test = test_info['test']
test_passed = test_info['is_passed']
testing.test_passed = test_passed
testing.save()
# Testing.objects.update_or_create(user=user,
# test=test,
# defaults = {"test_passed":test_passed})
def get_test_info(self, answer_ids, test_id):
"""Calculates test results from a list of answer IDs."""
@@ -537,7 +532,7 @@ class TestResultView(generics.ListCreateAPIView):
pass_perc = test.pass_perc
correct_answers_perc = 0
if answered_questions_total !=0:
correct_answers_perc = (correct_questions/answered_questions_total*100)
correct_answers_perc = correct_questions/answered_questions_total*100
result = {
"is_passed": correct_answers_perc >= pass_perc,
"score": correct_questions,
@@ -555,7 +550,7 @@ class GetUsers(APIView):
Комментарий
"""
def get(self, request):
def get(self):
"""
Комментарий
"""