瀏覽代碼

练习题记录、提交

wushaodong 3 年之前
父節點
當前提交
a4269d4165
共有 2 個文件被更改,包括 11 次插入4 次删除
  1. 2 3
      apps/api/staff/practise/views.py
  2. 9 1
      apps/practise/practiselog/serializers.py

+ 2 - 3
apps/api/staff/practise/views.py

@@ -61,7 +61,7 @@ class PractiseLogViewSet(CustomModelViewSet):
     def get_next_practise(self, request, pk):
         now_practise = request.data.get('now_practise')  # 当前提交的练习题。第一题或继续答题时,该参数为空
         answers = json.loads(request.data.get('answers'))  # 答案, 第一题或继续答题时,该参数为空
-        next_number = int(request.data.get('next_number')) or 0  # 下一题序号, 第一题提交为空,不在使用
+        next_number = request.data.get('next_number') or 0  # 下一题序号, 第一题提交为空,不在使用
         next_practise = request.data.get('next_practise')  # 下一题id,首次加载第一题,传空
         try:
             with transaction.atomic():
@@ -145,7 +145,6 @@ class PractiseLogViewSet(CustomModelViewSet):
                         'type')
                 else:
                     questions = ExamQuestion.objects.filter(chapter=instance.chapter, delete=False).order_by('type')
-
                 # 返回下一题
                 if next_practise:
                     question = questions.filter(id=next_practise).first()
@@ -158,7 +157,7 @@ class PractiseLogViewSet(CustomModelViewSet):
                         'id': question.id,
                         'title': question.title,
                         'next_type': question.type,  # 下一题习题类别
-                        'next_number': next_number + 1,  # 下下一题序号,
+                        'next_number': int(next_number) + 1,  # 下下一题序号,
                         'option': [],
                     }
                     answer_log = PractiseAnswerLog.objects.filter(main=instance, question=question).first()

+ 9 - 1
apps/practise/practiselog/serializers.py

@@ -14,6 +14,10 @@ class PractiseLogSerializer(serializers.ModelSerializer):
         if obj.end_answer:
             now_type = obj.end_answer.question.type
             questions = ExamQuestion.objects.filter(type=now_type, delete=False).order_by('id').values_list('id', flat=True)
+            if obj.chapter:
+                questions = questions.filter(chapter=obj.chapter)
+            else:
+                questions = questions.filter(chapter__subject=obj.subject)
             now_question_index = list(questions).index(obj.end_answer.question.id)
             if now_question_index < (len(questions) -1):
                 # 该题型未练习完,继续返回该题型下的习题
@@ -23,6 +27,10 @@ class PractiseLogSerializer(serializers.ModelSerializer):
                 while now_type <= ExamQuestion.JUDGMENT:
                     now_type += 1
                     questions = ExamQuestion.objects.filter(type=now_type, delete=False).order_by('id').first()
+                    if obj.chapter:
+                        questions = questions.filter(chapter=obj.chapter)
+                    else:
+                        questions = questions.filter(chapter__subject=obj.subject)
                     if questions:
                         next_practise = questions.id
                         break
@@ -31,7 +39,7 @@ class PractiseLogSerializer(serializers.ModelSerializer):
     def get_end_answer(self, obj):
         if obj.end_answer:
             now_type = obj.end_answer.question.type
-            # todo
+            # todo 按id查
             questions = ExamQuestion.objects.filter(type=now_type, delete=False).order_by('id').values_list('id', flat=True)
             now_question_index = list(questions).index(obj.end_answer.question.id)
             name = '{0}/{1} {2}第{3}题'.format(obj.end_answer.question.chapter.name,