|
@@ -18,7 +18,11 @@ class PractiseLogSerializer(serializers.ModelSerializer):
|
|
|
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)
|
|
|
+ try:
|
|
|
+ # ValueError: 1 is not in list
|
|
|
+ now_question_index = list(questions).index(obj.end_answer.question.id)
|
|
|
+ except ValueError:
|
|
|
+ now_question_index = 0
|
|
|
if now_question_index < (len(questions) -1):
|
|
|
# 该题型未练习完,继续返回该题型下的习题
|
|
|
next_practise = questions[now_question_index + 1]
|
|
@@ -26,11 +30,12 @@ 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()
|
|
|
+ questions = ExamQuestion.objects.filter(type=now_type, delete=False)
|
|
|
if obj.chapter:
|
|
|
questions = questions.filter(chapter=obj.chapter)
|
|
|
else:
|
|
|
questions = questions.filter(chapter__subject=obj.subject)
|
|
|
+ questions = questions.order_by('id').first()
|
|
|
if questions:
|
|
|
next_practise = questions.id
|
|
|
break
|
|
@@ -41,7 +46,15 @@ class PractiseLogSerializer(serializers.ModelSerializer):
|
|
|
now_type = obj.end_answer.question.type
|
|
|
# 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)
|
|
|
+ if obj.chapter:
|
|
|
+ questions = questions.filter(chapter=obj.chapter)
|
|
|
+ else:
|
|
|
+ questions = questions.filter(chapter__subject=obj.subject)
|
|
|
+ try:
|
|
|
+ # ValueError: 1 is not in list
|
|
|
+ now_question_index = list(questions).index(obj.end_answer.question.id)
|
|
|
+ except ValueError:
|
|
|
+ now_question_index = 0
|
|
|
name = '{0}/{1} {2}第{3}题'.format(obj.end_answer.question.chapter.name,
|
|
|
obj.end_answer.question.chapter.subject.name,
|
|
|
ExamQuestion.TYPE_CHOICES[obj.end_answer.question.type - 1][1],
|
|
@@ -54,7 +67,15 @@ class PractiseLogSerializer(serializers.ModelSerializer):
|
|
|
if obj.begin_answer:
|
|
|
now_type = obj.begin_answer.question.type
|
|
|
questions = ExamQuestion.objects.filter(type=now_type, delete=False).order_by('id').values_list('id', flat=True)
|
|
|
- now_question_index = list(questions).index(obj.begin_answer.question.id)
|
|
|
+ if obj.chapter:
|
|
|
+ questions = questions.filter(chapter=obj.chapter)
|
|
|
+ else:
|
|
|
+ questions = questions.filter(chapter__subject=obj.subject)
|
|
|
+ try:
|
|
|
+ # ValueError: 1 is not in list
|
|
|
+ now_question_index = list(questions).index(obj.begin_answer.question.id)
|
|
|
+ except ValueError:
|
|
|
+ now_question_index = 0
|
|
|
name = '{0}/{1} {2}第{3}题'.format(obj.begin_answer.question.chapter.name,
|
|
|
obj.begin_answer.question.chapter.subject.name,
|
|
|
ExamQuestion.TYPE_CHOICES[obj.begin_answer.question.type - 1][1],
|