изменения в tests/views
This commit is contained in:
1 parent
d11cf3ed52
commit
9427077d37
2 files changed
+4
-45
No files matched your search
@@ -63,7 +63,6 @@ class Testing(models.Model):
|
||||
return self.test.name
|
||||
|
||||
class TestAttempt(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='test_attempts')
|
||||
testing = models.ForeignKey(Testing, on_delete=models.CASCADE)
|
||||
score = models.FloatField(verbose_name='Результат', default=0.0)
|
||||
attempt_number = models.IntegerField(verbose_name='Номер попытки', default=1)
|
||||
|
||||
+4
-44
@@ -55,8 +55,7 @@ class GetTests(generics.ListAPIView):
|
||||
return status_filters.get(status, Test.objects.none()).order_by('dateend')
|
||||
|
||||
def set_attemps_number(self, user, tests):
|
||||
test_ids = [test.id for test in tests]
|
||||
attempt_counts = TestAttempt.objects.filter(testing__user=user, testing__test__id__in=test_ids).values('testing__test').annotate(count=Count('testing__test'))
|
||||
attempt_counts = TestAttempt.objects.filter(testing__user=user, testing__test__in=tests).values('testing__test').annotate(count=Count('testing__test'))
|
||||
attempt_counts = {item['testing__test']: item['count'] for item in attempt_counts}
|
||||
|
||||
for test in tests:
|
||||
@@ -77,44 +76,6 @@ class TestDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
|
||||
return Response(test_serialized)
|
||||
|
||||
# class TestListCreate(generics.ListCreateAPIView):
|
||||
# queryset = Test.objects.all()
|
||||
# serializer_class = TestSerializer
|
||||
|
||||
# def get(self, request):
|
||||
# user = request.user
|
||||
# now = datetime.now()
|
||||
# status = request.query_params.get('status')
|
||||
# tests = self.get_tests_by_status(status, now)
|
||||
# serialized_tests = TestSerializer(tests, many=True).data
|
||||
# questions = TestQuestion.objects.filter(test__in=tests)
|
||||
|
||||
# questions_by_test_id = defaultdict(list)
|
||||
# for question in questions:
|
||||
# questions_by_test_id[question.test.id].append(question)
|
||||
|
||||
# for test in serialized_tests:
|
||||
# test['is_passed'] = self.has_participated(user, test['id'])
|
||||
# related_questions = questions_by_test_id[test['id']]
|
||||
# test['files'] = [question.file.url for question in related_questions if question.file]
|
||||
|
||||
# return Response(serialized_tests)
|
||||
|
||||
# def get_tests_by_status(self, status, now):
|
||||
# print(status)
|
||||
# if status is None:
|
||||
# return Test.objects.all().order_by('dateend')
|
||||
|
||||
# status_filters = {
|
||||
# 'active': Test.objects.filter(dateend__gt=now),
|
||||
# 'completed': Test.objects.filter(dateend__lt=now),
|
||||
# }
|
||||
|
||||
# return status_filters.get(status, Test.objects.none()).order_by('dateend')
|
||||
|
||||
# def has_participated(self, employee, test):
|
||||
# return TestResult.objects.filter(user=employee, answer__question__test=test).exists()
|
||||
|
||||
class GetTesting(APIView):
|
||||
|
||||
def get(self, request):
|
||||
@@ -133,11 +94,10 @@ class TestResultCreate(generics.ListCreateAPIView):
|
||||
serializer_class = TestResultSerializer
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
user = request.user
|
||||
# user = User.objects.get(username = "9966-00-125")
|
||||
# user = request.user
|
||||
user = User.objects.get(username = "9966-00-125")
|
||||
test_id = request.GET.get('id')
|
||||
testing = Testing.objects.filter(user=user, test__id=test_id)
|
||||
last_attempt = TestAttempt.objects.filter(testing=testing).order_by('-completion_date').first()
|
||||
last_attempt = TestAttempt.objects.filter(testing__user=user, testing__test__id=test_id).order_by('-completion_date').first()
|
||||
answer_ids = TestResult.objects.filter(attempt=last_attempt).values_list('answer__id', flat=True)
|
||||
test_info = self.get_test_info(answer_ids)
|
||||
return Response(data={'score': test_info['score'], 'answered_questions_total': test_info['answered_questions_total']})
|
||||
|
||||
Reference in new issue
Block a user