|
@@ -82,11 +82,9 @@ class PractiseLogViewSet(CustomModelViewSet):
|
|
|
right = ExamQuestionOption.objects.filter(main=now_question, id=answer, right=True,
|
|
|
delete=False)
|
|
|
if right:
|
|
|
- instance.right_count += 1
|
|
|
answer_log.status = PractiseAnswerLog.RIGHT
|
|
|
else:
|
|
|
answer_log.status = PractiseAnswerLog.WRONG
|
|
|
- instance.wrong_count += 1
|
|
|
elif now_question.type == ExamQuestion.MULTIPLE:
|
|
|
# 多选
|
|
|
answers.sort()
|
|
@@ -98,10 +96,8 @@ class PractiseLogViewSet(CustomModelViewSet):
|
|
|
list(right).sort()
|
|
|
if answers == right:
|
|
|
answer_log.status = PractiseAnswerLog.RIGHT
|
|
|
- instance.right_count += 1
|
|
|
else:
|
|
|
answer_log.status = PractiseAnswerLog.WRONG
|
|
|
- instance.wrong_count += 1
|
|
|
elif now_question.type == ExamQuestion.FILL:
|
|
|
# 填空
|
|
|
answers_len = len(answers)
|
|
@@ -116,18 +112,14 @@ class PractiseLogViewSet(CustomModelViewSet):
|
|
|
right = 0
|
|
|
if right:
|
|
|
answer_log.status = PractiseAnswerLog.RIGHT
|
|
|
- instance.right_count += 1
|
|
|
else:
|
|
|
answer_log.status = PractiseAnswerLog.WRONG
|
|
|
- instance.wrong_count += 1
|
|
|
else:
|
|
|
# 判断
|
|
|
if now_question.judgment == (answers[0] == 1):
|
|
|
answer_log.status = PractiseAnswerLog.RIGHT
|
|
|
- instance.right_count += 1
|
|
|
else:
|
|
|
answer_log.status = PractiseAnswerLog.WRONG
|
|
|
- instance.wrong_count += 1
|
|
|
instance.total_count += 1
|
|
|
# 第一题
|
|
|
if not instance.begin_answer:
|
|
@@ -209,7 +201,8 @@ class PractiseLogViewSet(CustomModelViewSet):
|
|
|
questions = questions.values_list('id', flat=True)
|
|
|
single_questions_list = []
|
|
|
for single in questions.filter(type=ExamQuestion.SINGLE):
|
|
|
- answer_log = PractiseAnswerLog.objects.filter(main=instance, question_id=single, status__isnull=False)
|
|
|
+ answer_log = PractiseAnswerLog.objects.filter(main=instance, question_id=single,
|
|
|
+ status__isnull=False)
|
|
|
single_questions_list.append(
|
|
|
{
|
|
|
'question_id': single,
|
|
@@ -219,7 +212,8 @@ class PractiseLogViewSet(CustomModelViewSet):
|
|
|
# 多选题
|
|
|
multiple_questions_list = []
|
|
|
for multiple in questions.filter(type=ExamQuestion.MULTIPLE):
|
|
|
- answer_log = PractiseAnswerLog.objects.filter(main=instance, question_id=multiple, status__isnull=False)
|
|
|
+ answer_log = PractiseAnswerLog.objects.filter(main=instance, question_id=multiple,
|
|
|
+ status__isnull=False)
|
|
|
multiple_questions_list.append(
|
|
|
{
|
|
|
'question_id': multiple,
|
|
@@ -260,6 +254,26 @@ class PractiseLogViewSet(CustomModelViewSet):
|
|
|
traceback.print_exc()
|
|
|
return response_error(str(e))
|
|
|
|
|
|
+ @action(methods=['post'], detail=True)
|
|
|
+ def submit_practise(self, request, pk):
|
|
|
+ # 习题交卷
|
|
|
+ try:
|
|
|
+ instance = self.get_object()
|
|
|
+
|
|
|
+ with transaction.atomic():
|
|
|
+ right_count = PractiseAnswerLog.objects.filter(main=instance, status=PractiseAnswerLog.RIGHT).count()
|
|
|
+ wrong_count = PractiseAnswerLog.objects.filter(main=instance, status=PractiseAnswerLog.WRONG).count()
|
|
|
+ instance.right_count = right_count
|
|
|
+ instance.wrong_count = wrong_count
|
|
|
+ instance.submit_time = timezone.now()
|
|
|
+ instance.save()
|
|
|
+ SysLog.objects.addnew(request.user, SysLog.INSERT, u"提交习题答案,id=%d" % (instance.id))
|
|
|
+ except CustomError as e:
|
|
|
+ return response_error(e.get_error_msg())
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ return response_error(str(e))
|
|
|
+ return response_ok()
|
|
|
|
|
|
class DictView(APIView):
|
|
|
permission_classes = [IsStaff, ]
|