|
@@ -59,12 +59,12 @@ class PractiseLogViewSet(CustomModelViewSet):
|
|
|
|
|
|
@action(methods=['post'], detail=True)
|
|
|
def get_next_practise(self, request, pk):
|
|
|
- now_practise = request.data.get('now_practise') # 当前提交的练习题, 第一题或继续答题时,该参数为空
|
|
|
+ now_practise = request.data.get('now_practise') # 当前提交的练习题。第一题或继续答题时,该参数为空
|
|
|
answers = json.loads(request.data.get('answers')) # 答案, 第一题或继续答题时,该参数为空
|
|
|
- next_number = int(request.data.get('next_number')) # 下一题序号,最后一题提交时,此参数为0
|
|
|
- next_type = int(request.data.get('next_type')) # 下一题题型,默认1为单选题
|
|
|
+ next_number = int(request.data.get('next_number')) or 0 # 下一题序号, 第一题提交为空
|
|
|
+ # next_type = int(request.data.get('next_type')) # 下一题题型,默认1为单选题
|
|
|
button_type = request.data.get('button_type') # 上一题、下一题按钮类型,next下一题,previous上一题
|
|
|
- previous_practise = request.data.get('previous_practise') # 上一题id
|
|
|
+ next_practise = request.data.get('next_practise') # 下一题id,首次加载第一题,传空
|
|
|
try:
|
|
|
with transaction.atomic():
|
|
|
instance = self.get_object()
|
|
@@ -133,20 +133,17 @@ class PractiseLogViewSet(CustomModelViewSet):
|
|
|
instance.end_answer = answer_log
|
|
|
instance.submit_time = timezone.now()
|
|
|
instance.save()
|
|
|
- answer_log.order = next_number
|
|
|
answer_log.save()
|
|
|
|
|
|
question_data = {}
|
|
|
- if previous_practise:
|
|
|
- # 上一题
|
|
|
- questions = ExamQuestion.objects.filter(id=previous_practise)
|
|
|
- elif instance.type == PractiseLog.SUBJECT:
|
|
|
+ if instance.type == PractiseLog.SUBJECT:
|
|
|
questions = ExamQuestion.objects.filter(chapter__subject=instance.subject, delete=False).order_by(
|
|
|
'type')
|
|
|
else:
|
|
|
questions = ExamQuestion.objects.filter(chapter=instance.chapter, delete=False).order_by('type')
|
|
|
+
|
|
|
# 返回下一题
|
|
|
- if next_number:
|
|
|
+ if next_practise:
|
|
|
# 循环查询4个题型的试题,只到查询到试题
|
|
|
# question = None
|
|
|
# while not question and next_type <= ExamQuestion.JUDGMENT:
|
|
@@ -155,9 +152,11 @@ class PractiseLogViewSet(CustomModelViewSet):
|
|
|
# break
|
|
|
# next_type += 1
|
|
|
# next_number = 1
|
|
|
- question = questions.filter()[next_number - 1:next_number].first()
|
|
|
+ question = questions.filter(id=next_practise).first()
|
|
|
+ else:
|
|
|
+ question = questions.filter().first()
|
|
|
|
|
|
- if question:
|
|
|
+ if question:
|
|
|
# 查询到下一题,返回题目和答案
|
|
|
# 根据下一题,查询下下一题类型
|
|
|
# next_question = None
|
|
@@ -177,9 +176,8 @@ class PractiseLogViewSet(CustomModelViewSet):
|
|
|
question_data = {
|
|
|
'id': question.id,
|
|
|
'title': question.title,
|
|
|
- 'next_type': question.type, # 下一题类别 id,不在使用
|
|
|
- 'next_number': next_number + 1, # 下下一题序号,如果为0,则没有下一题了
|
|
|
- 'previous_practise': now_practise, # 上一题 id
|
|
|
+ 'next_type': question.type, # 下一题习题类别
|
|
|
+ 'next_number': next_number + 1, # 下下一题序号,
|
|
|
'option': [],
|
|
|
}
|
|
|
answer_log = PractiseAnswerLog.objects.filter(main=instance, question=question).first()
|