fix [P-256]: мердж

This commit is contained in:
Nukeap committed 2025-06-03 14:50:18 +03:00
commit 4cb0d47d23
5 files changed
+61 -20

No files matched your search

+8 -1
View File
@@ -93,7 +93,14 @@ class TestAttemptSerializer(serializers.ModelSerializer):
class TestResultSerializer(serializers.ModelSerializer):
attempt = TestAttemptSerializer(read_only=True)
answer = serializers.PrimaryKeyRelatedField(queryset=TestAnswer.objects.all(), many=False)
question = serializers.PrimaryKeyRelatedField(
queryset=TestQuestion.objects.all(),
allow_null=True
)
answer = serializers.PrimaryKeyRelatedField(
queryset=TestAnswer.objects.all(),
allow_null=True,
many=False)
comment = serializers.CharField(allow_null=True, required=False)
class Meta:
+42 -15
View File
@@ -418,23 +418,50 @@ class TestResultView(generics.ListCreateAPIView):
)
def post(self, request, *args, **kwargs):
"""Saves the results of a new test attempt."""
user = request.user
# user = User.objects.get(username = "9966-00-125")
status = request.query_params.get('status')
test_id = request.query_params.get('id')
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)
try:
user = request.user
# user = User.objects.get(username = "9966-00-125")
status = request.query_params.get('status')
test_id = request.query_params.get('id')
answer_ids = []
prepared_data = []
for data in request.data:
question_id = data.get('question_id')
answers_id = data.get('answers_id', [])
for sublist in answers_id:
if isinstance(sublist, list):
answer_ids.extend(sublist)
else:
answer_ids.append(sublist)
if answers_id:
for answer_id in answers_id:
prepared_data.append({
'question': question_id,
'answer': answer_id,
})
else:
prepared_data.append({
'question': question_id,
'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)
serializer = self.get_serializer(data=request.data, many=True)
if serializer.is_valid():
serializer.save(attempt=test_attempt)
self.update_testing(user, test_info, testing)
# serializer = self.get_serializer(data=request.data, many=True)
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)
return Response(data={'score': test_info['score'],
'answered_questions_total': test_info['answered_questions_total'],
'is_passed': test_info['is_passed']})
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:
print(e)
return Response({"status": "error", "message": str(e)}, status=400)
def create_test_attempt(self, user, test_info):
"""Creates a new test attempt for the user."""
@@ -67,10 +67,17 @@
</v-row>
</v-card>
<!-- Если данные отсутствуют, выводим сообщение об этом -->
<v-container v-if="!searchTest.length" :fluid="true" class="empty-state">
<v-row class="align-center flex-column pa-8">
<v-container
v-if="!searchTest.length"
:fluid="true"
class="empty-state"
style="min-height: 70vh;"
>
<v-row class="align-center flex-column pa-8" style="min-height: 300px;">
<v-icon icon="mdi-note-off-outline" color="grey-lighten-1" size="64" class="mb-4" />
<v-card-title class="text-h5 text-grey-darken-1 font-weight-medium text-center">Данные не найдены</v-card-title>
<v-card-title class="text-h5 text-grey-darken-1 font-weight-medium text-center">
Данные не найдены
</v-card-title>
</v-row>
</v-container>
</template>
@@ -36,7 +36,7 @@
<v-tooltip location="bottom">
<template v-slot:activator="{ props }">
<v-btn icon @click="toggleTheme">
<v-icon v-bind="props" class="mr-1" color="lampa">
<v-icon v-bind="props" class="mr-1" :color="theme.global.current.value.dark ? 'yellow' : 'lampa'">
mdi-lightbulb-outline
</v-icon>
</v-btn>