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

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

No files matched your search

+8 -1
View File
@@ -93,7 +93,14 @@ class TestAttemptSerializer(serializers.ModelSerializer):
class TestResultSerializer(serializers.ModelSerializer): class TestResultSerializer(serializers.ModelSerializer):
attempt = TestAttemptSerializer(read_only=True) 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) comment = serializers.CharField(allow_null=True, required=False)
class Meta: class Meta:
+29 -2
View File
@@ -418,16 +418,40 @@ class TestResultView(generics.ListCreateAPIView):
) )
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
"""Saves the results of a new test attempt.""" """Saves the results of a new test attempt."""
try:
user = request.user user = request.user
# user = User.objects.get(username = "9966-00-125") # user = User.objects.get(username = "9966-00-125")
status = request.query_params.get('status') status = request.query_params.get('status')
test_id = request.query_params.get('id') test_id = request.query_params.get('id')
answer_ids = [item['answer'] for item in request.data] 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) test_info = self.get_test_info(answer_ids, test_id)
if status == 'testing': if status == 'testing':
test_attempt, testing = self.create_test_attempt(user, test_info) test_attempt, testing = self.create_test_attempt(user, test_info)
serializer = self.get_serializer(data=request.data, many=True) # serializer = self.get_serializer(data=request.data, many=True)
serializer = self.get_serializer(data=prepared_data, many=True)
if serializer.is_valid(): if serializer.is_valid():
serializer.save(attempt=test_attempt) serializer.save(attempt=test_attempt)
self.update_testing(user, test_info, testing) self.update_testing(user, test_info, testing)
@@ -435,6 +459,9 @@ class TestResultView(generics.ListCreateAPIView):
return Response(data={'score': test_info['score'], return Response(data={'score': test_info['score'],
'answered_questions_total': test_info['answered_questions_total'], 'answered_questions_total': test_info['answered_questions_total'],
'is_passed': test_info['is_passed']}) '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): def create_test_attempt(self, user, test_info):
"""Creates a new test attempt for the user.""" """Creates a new test attempt for the user."""
@@ -67,10 +67,17 @@
</v-row> </v-row>
</v-card> </v-card>
<!-- Если данные отсутствуют, выводим сообщение об этом --> <!-- Если данные отсутствуют, выводим сообщение об этом -->
<v-container v-if="!searchTest.length" :fluid="true" class="empty-state"> <v-container
<v-row class="align-center flex-column pa-8"> 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-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-row>
</v-container> </v-container>
</template> </template>
@@ -36,7 +36,7 @@
<v-tooltip location="bottom"> <v-tooltip location="bottom">
<template v-slot:activator="{ props }"> <template v-slot:activator="{ props }">
<v-btn icon @click="toggleTheme"> <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 mdi-lightbulb-outline
</v-icon> </v-icon>
</v-btn> </v-btn>