Browse Source

论述题错题集

wushaodong 2 years ago
parent
commit
ec7b064bb4

+ 12 - 2
apps/api/admin/exam/views.py

@@ -17,6 +17,7 @@ from apps.examination.exampaper.serializers import ExamPaperSerializer
 from apps.examination.exam.models import Exam, ExamLog, ExamAnswerLog
 from apps.examination.exam.filters import ExamFilter, FormalExamLogFilter
 from apps.examination.exam.serializers import ExamSerializer, FormalExamLogSerializer
+from apps.practise.errorbook.models import ErrorBook
 
 class ExamViewSet(CustomModelViewSet):
     permission_classes = [IsAdministrator, ]
@@ -159,8 +160,17 @@ class ExamLogViewSet(ReadOnlyModelViewSet):
                 for item in items:
                     discuss_scores = int(item['user_scores'])
                     discuss_answer_scores += discuss_scores
-                    ExamAnswerLog.objects.filter(id=item['id'], status=ExamAnswerLog.WAIT_CHECK).\
-                        update(status=ExamAnswerLog.NOTDONE, discuss_scores=discuss_scores)
+                    exam_log = ExamAnswerLog.objects.filter(id=item['id'], status=ExamAnswerLog.WAIT_CHECK).first()
+                    if exam_log:
+                        exam_log.discuss_scores=discuss_scores
+                        if discuss_scores == exam_log.detail.main.discuss_scores:
+                            exam_log.status = ExamAnswerLog.RIGHT
+                        else:
+                            exam_log.status = ExamAnswerLog.WRONG
+                            ErrorBook.add_error(exam_log.detail.question, exam_log.main.user, exam_log)
+                        exam_log.save()
+                    else:
+                        raise CustomError('该题可能已经评分结束,请刷新后重试!')
                 instance.discuss_answer_scores = discuss_answer_scores
                 instance.scores += discuss_answer_scores
                 instance.save()

+ 2 - 0
apps/examination/exam/serializers.py

@@ -175,6 +175,8 @@ class ExamAnswerLogSimpleSerializer(serializers.ModelSerializer):
         elif obj.detail.question.type == ExamQuestion.FILL:
             rows = ExamAnswerFillLog.objects.filter(main=obj)
             return ExamAnswerFillLogSimpleSerializer(rows, many=True).data
+        elif obj.detail.question.type == ExamQuestion.DISCUSS:
+            return [{'content':obj.discuss_answer, 'order':1}]
         else:
             return []
 

+ 2 - 0
apps/examination/examquestion/serializers.py

@@ -147,6 +147,8 @@ class ExamQuestionSimpleSerializer(serializers.ModelSerializer):
         elif obj.type == ExamQuestion.FILL:
             rows = ExamQuestionFill.objects.filter(main=obj, delete=False)
             return ExamQuestionFillSimpleSerializer(rows, many=True).data
+        elif obj.type == ExamQuestion.DISCUSS:
+            return [{'content':obj.discuss_answer, 'order':1}]
         else:
             return []
 

+ 1 - 1
uis/admin/examlog/index.html

@@ -189,7 +189,7 @@
                     yes: function (index, dom) {
                         layui.onSubmitChild = function (res) {
                             layer.close(index);
-                            table.reload('exam_datagrid', {});
+                            table.reload('exampaper_datagrid', {});
                         };
                         layui.submitChild();
                     },