|
@@ -20,6 +20,7 @@ from apps.examination.exampaper.models import ExamPaper, ExamPaperDetail, ExamQu
|
|
|
from apps.examination.exampaper.filters import ExamPaperFilter
|
|
|
from apps.examination.exampaper.serializers import StaffExamPaperSerializer
|
|
|
from apps.examination.examquestion.models import ExamQuestionOption, ExamQuestionFill
|
|
|
+from apps.practise.errorbook.models import ErrorBook
|
|
|
|
|
|
class ExamPaperViewSet(CustomModelViewSet):
|
|
|
permission_classes = [IsStaff, ]
|
|
@@ -59,6 +60,10 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
result = {
|
|
|
'exam_log': instance.id, # 模拟考试 id
|
|
|
}
|
|
|
+ # 创建模拟考试答题记录
|
|
|
+ paper_details = ExamPaperDetail.objects.filter(main=exampaper, delete=False)
|
|
|
+ for detail in paper_details:
|
|
|
+ ExamAnswerLog.objects.create(main=instance, detail=detail)
|
|
|
return response_ok(result)
|
|
|
except ValidationError as e:
|
|
|
traceback.print_exc()
|
|
@@ -79,61 +84,36 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
raise CustomError('提交的考试习题有误,请刷新重试!')
|
|
|
now_question = detail.question
|
|
|
if len(answers) > 0:
|
|
|
- answer_log, create = ExamAnswerLog.objects.get_or_create(main=instance,
|
|
|
- detail=detail,)
|
|
|
- if now_question.type == ExamQuestion.SINGLE:
|
|
|
- # 单选
|
|
|
- ExamAnswerOptionLog.objects.filter(main=answer_log).delete()
|
|
|
- answer = answers[0]
|
|
|
- ExamAnswerOptionLog.objects.create(main=answer_log, option_id=answer)
|
|
|
- right = ExamQuestionOption.objects.filter(main=now_question, id=answer, right=True,
|
|
|
- delete=False)
|
|
|
- if right:
|
|
|
- answer_log.status = ExamAnswerLog.RIGHT
|
|
|
- else:
|
|
|
- answer_log.status = ExamAnswerLog.WRONG
|
|
|
- elif now_question.type == ExamQuestion.MULTIPLE:
|
|
|
- # 多选
|
|
|
+ try:
|
|
|
+ answer_log = ExamAnswerLog.objects.get(main=instance, detail=detail)
|
|
|
+ except ExamAnswerLog.DoesNotExist:
|
|
|
+ # traceback.print_exc()
|
|
|
+ raise CustomError('考试习题有误,请刷新重试!')
|
|
|
+ if now_question.type <= ExamQuestion.MULTIPLE:
|
|
|
+ # 单选、多选
|
|
|
answers.sort()
|
|
|
ExamAnswerOptionLog.objects.filter(main=answer_log).delete()
|
|
|
for a in answers:
|
|
|
ExamAnswerOptionLog.objects.create(main=answer_log, option_id=a)
|
|
|
- right = ExamQuestionOption.objects.filter(main=now_question, right=True,
|
|
|
- delete=False).values_list('id', flat=True)
|
|
|
- list(right).sort()
|
|
|
- if answers == right:
|
|
|
- answer_log.status = ExamAnswerLog.RIGHT
|
|
|
- else:
|
|
|
- answer_log.status = ExamAnswerLog.WRONG
|
|
|
elif now_question.type == ExamQuestion.FILL:
|
|
|
# 填空
|
|
|
answers_len = len(answers)
|
|
|
- right = 1
|
|
|
ExamAnswerFillLog.objects.filter(main=answer_log).delete()
|
|
|
for a in range(0, answers_len):
|
|
|
ExamAnswerFillLog.objects.create(main=answer_log, content=answers[a], order=a + 1)
|
|
|
- right_answer = ExamQuestionFill.objects.filter(main=now_question, content=answers[a],
|
|
|
- order=a + 1)
|
|
|
- if not right_answer:
|
|
|
- # 有一个填空错误,整题错误
|
|
|
- right = 0
|
|
|
- if right:
|
|
|
- answer_log.status = ExamAnswerLog.RIGHT
|
|
|
- else:
|
|
|
- answer_log.status = ExamAnswerLog.WRONG
|
|
|
else:
|
|
|
# 判断
|
|
|
- if now_question.judgment == (answers[0] == 1):
|
|
|
+ if answers[0] == 1:
|
|
|
answer_log.status = ExamAnswerLog.RIGHT
|
|
|
else:
|
|
|
answer_log.status = ExamAnswerLog.WRONG
|
|
|
- answer_log.save()
|
|
|
+ answer_log.save()
|
|
|
else:
|
|
|
try:
|
|
|
- answer_log = ExamAnswerLog.objects.get(main=instance, question=now_question, )
|
|
|
+ answer_log = ExamAnswerLog.objects.get(main=instance, detail=detail)
|
|
|
ExamAnswerOptionLog.objects.filter(main=answer_log).delete()
|
|
|
ExamAnswerFillLog.objects.filter(main=answer_log).delete()
|
|
|
- answer_log.status = None
|
|
|
+ answer_log.status = ExamAnswerLog.NOTDONE
|
|
|
answer_log.save()
|
|
|
except ExamAnswerLog.DoesNotExist:
|
|
|
# traceback.print_exc()
|
|
@@ -142,7 +122,8 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
question_data = {}
|
|
|
# 返回下一题
|
|
|
if next_practise:
|
|
|
- detail = ExamPaperDetail.objects.filter(id=next_practise, main=instance.exampaper, delete=False).first()
|
|
|
+ detail = ExamPaperDetail.objects.filter(id=next_practise, main=instance.exampaper,
|
|
|
+ delete=False).first()
|
|
|
else:
|
|
|
detail = ExamPaperDetail.objects.filter(main=instance.exampaper, delete=False).first()
|
|
|
|
|
@@ -192,7 +173,8 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
|
|
|
# 右侧习题类别列表
|
|
|
# 单选、多选、填空。选择答案后,可能会把答案清空,得加上NOTDONE过滤
|
|
|
- questions = ExamPaperDetail.objects.filter(main=instance.exampaper, delete=False).values_list('id', flat=True)
|
|
|
+ questions = ExamPaperDetail.objects.filter(main=instance.exampaper, delete=False).values_list('id',
|
|
|
+ flat=True)
|
|
|
single_questions_list = []
|
|
|
for single in questions.filter(question__type=ExamQuestion.SINGLE):
|
|
|
answer_log = ExamAnswerLog.objects.filter(main=instance, detail=single).exclude(
|
|
@@ -266,17 +248,22 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
if answers:
|
|
|
if answers.option.right:
|
|
|
answer_log.status = ExamAnswerLog.RIGHT
|
|
|
+ instance.single_answer_count += 1
|
|
|
else:
|
|
|
answer_log.status = ExamAnswerLog.WRONG
|
|
|
+ ErrorBook.add_error(question, request.user, answer_log)
|
|
|
elif question.type == ExamQuestion.MULTIPLE:
|
|
|
# 多选
|
|
|
- answers = ExamAnswerOptionLog.objects.filter(main=answer_log).order_by('option_id').values_list('option_id', flat=True)
|
|
|
+ answers = ExamAnswerOptionLog.objects.filter(main=answer_log).order_by('option_id').values_list(
|
|
|
+ 'option_id', flat=True)
|
|
|
right = ExamQuestionOption.objects.filter(main=question, right=True,
|
|
|
delete=False).values_list('id', flat=True)
|
|
|
if list(answers) == list(right):
|
|
|
answer_log.status = ExamAnswerLog.RIGHT
|
|
|
+ instance.multiple_answer_count += 1
|
|
|
else:
|
|
|
answer_log.status = ExamAnswerLog.WRONG
|
|
|
+ ErrorBook.add_error(question, request.user, answer_log)
|
|
|
elif question.type == ExamQuestion.FILL:
|
|
|
# 填空
|
|
|
fill_logs = ExamAnswerFillLog.objects.filter(main=answer_log)
|
|
@@ -289,19 +276,40 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
break
|
|
|
if right:
|
|
|
answer_log.status = ExamAnswerLog.RIGHT
|
|
|
+ instance.fill_answer_count += 1
|
|
|
else:
|
|
|
answer_log.status = ExamAnswerLog.WRONG
|
|
|
+ ErrorBook.add_error(question, request.user, answer_log)
|
|
|
else:
|
|
|
# 判断
|
|
|
if question.judgment == (answer_log.status == ExamAnswerLog.RIGHT):
|
|
|
answer_log.status = ExamAnswerLog.RIGHT
|
|
|
+ instance.judgment_answer_count += 1
|
|
|
else:
|
|
|
answer_log.status = ExamAnswerLog.WRONG
|
|
|
+ ErrorBook.add_error(question, request.user, answer_log)
|
|
|
answer_log.save()
|
|
|
|
|
|
instance.submit_time = timezone.now()
|
|
|
+ use_time = instance.exam_time - instance.submit_time
|
|
|
+ instance.use_time = use_time.seconds
|
|
|
+
|
|
|
+ single_answer_scores = instance.single_answer_count * instance.exampaper.single_scores
|
|
|
+ multiple_answer_scores = instance.multiple_answer_count * instance.exampaper.multiple_scores
|
|
|
+ fill_answer_scores = instance.fill_answer_count * instance.exampaper.fill_scores
|
|
|
+ judgment_answer_scores = instance.judgment_answer_count * instance.exampaper.judgment_scores
|
|
|
+
|
|
|
+ instance.single_answer_scores = single_answer_scores
|
|
|
+ instance.multiple_answer_scores = multiple_answer_scores
|
|
|
+ instance.fill_answer_scores = fill_answer_scores
|
|
|
+ instance.judgment_answer_scores = judgment_answer_scores
|
|
|
+ instance.scores = single_answer_scores + judgment_answer_scores + multiple_answer_scores + fill_answer_scores
|
|
|
instance.save()
|
|
|
- SysLog.objects.addnew(request.user, SysLog.INSERT, u"提交模拟考试题答案,id=%d" % (instance.id))
|
|
|
+
|
|
|
+ instance.exampaper.did_count += 1
|
|
|
+ instance.exampaper.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:
|
|
@@ -309,6 +317,7 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
return response_error(str(e))
|
|
|
return response_ok()
|
|
|
|
|
|
+
|
|
|
class DictView(APIView):
|
|
|
permission_classes = [IsStaff, ]
|
|
|
|