изменение в GetTests

This commit is contained in:
Cja committed 2025-01-30 10:45:05 +03:00
1 parent 789cebbbef
commit 0c568f796f
2 files changed
+9 -3

No files matched your search

+1 -1
View File
@@ -77,7 +77,7 @@ class TestResult(models.Model):
class Testing(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
test = models.ForeignKey(Test, on_delete=models.PROTECT, blank=False, verbose_name="Тест")
completion_date = models.DateField(blank=True, null=True, verbose_name="Дата завершения тестирования")
completion_date = models.DateTimeField(blank=True, null=True, verbose_name="Дата завершения тестирования")
test_passed = models.BooleanField(blank=False, verbose_name="Тест пройден")
class Meta:
+8 -2
View File
@@ -29,6 +29,8 @@ class GetTests(generics.ListAPIView):
# user = User.objects.get(username='9966-00-125')
status = request.query_params.get('status')
tests = self.get_tests_by_status(status, datetime.now(), user)
if status != None:
self.set_attemps_number(user, tests)
serialized_tests = self.get_serializer(tests, many=True).data
return Response(serialized_tests)
@@ -41,7 +43,7 @@ class GetTests(generics.ListAPIView):
status_filters = {
'active' : Test.objects.filter(
testing__user=user,
testing__completion_date__gt=now
testing__completion_date__gte=now
).distinct(),
'completed' : Test.objects.filter(
@@ -51,6 +53,10 @@ class GetTests(generics.ListAPIView):
}
return status_filters.get(status, Test.objects.none()).order_by('dateend')
def set_attemps_number(self, user, tests):
for test in tests:
test.attemps_number = get_attempt_count(user=user, test=test)
class TestDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Test.objects.all()
@@ -146,7 +152,7 @@ class TestResultCreate(generics.ListCreateAPIView):
def update_testing(self, user, test_info):
test = test_info['test']
test_passed = test_info['is_passed']
Testing.objects.update_or_create(user=user, test=test, completion_date= test.dateend, defaults = {"test_passed":test_passed})
Testing.objects.update_or_create(user=user, test=test, defaults = {"completion_date": test.dateend,"test_passed":test_passed})
def get_test_info(self, request):