feat:exam/view.py 增加抽卷考试
This commit is contained in:
parent
789479ddea
commit
09b52b2a7e
|
@ -530,6 +530,7 @@ class ExamViewSet(CreateUpdateCustomMixin, ModelViewSet):
|
|||
if chance_used > exam.chance:
|
||||
raise ParseError('考试机会已用完')
|
||||
if exam.paper:
|
||||
details = []
|
||||
er = ExamRecord()
|
||||
er.type = '正式考试'
|
||||
er.name = '正式考试' + datetime.now().strftime('%Y%m%d%H%M')
|
||||
|
@ -543,20 +544,27 @@ class ExamViewSet(CreateUpdateCustomMixin, ModelViewSet):
|
|||
er.save()
|
||||
ret = {}
|
||||
ret['examrecord'] = er.id
|
||||
if exam.paper.paper_types == 10:
|
||||
if exam.paper.paper_types == '押题':
|
||||
pqs = PaperQuestion.objects.filter(paper=exam.paper).order_by('id')
|
||||
for i in pqs:
|
||||
details.append(AnswerDetail(examrecord=er, question=i.question, total_score=i.total_score))
|
||||
else:
|
||||
# 查询此试卷有哪些分类
|
||||
cqs = exam.paper.category
|
||||
print(cqs)
|
||||
paper_obj = exam.paper.category.all()
|
||||
cqs = [i.id for i in paper_obj]
|
||||
# 查询随机组卷的单选、多选、判断各多少题和不同分类
|
||||
single_qs = Question.objects.filter(Q(type="单选") & Q(category__in=cqs)).order_by('?')[:exam.paper.danxuan_count]
|
||||
multiple_qs = Question.objects.filter(Q(type="多选") & Q(category__in=cqs)).order_by('?')[:exam.paper.duoxuan_count]
|
||||
judge_qs = Question.objects.filter(Q(type="判断") & Q(category__in=cqs)).order_by('?')[:exam.paper.panduan_count]
|
||||
pqs = list(single_qs) + list(multiple_qs) + list(judge_qs)
|
||||
details = []
|
||||
for i in pqs:
|
||||
details.append(AnswerDetail(examrecord=er, question=i.question, total_score=i.total_score))
|
||||
single_qs = Question.objects.filter(Q(type="单选") & Q(questioncat__in=cqs)).order_by('?')[:exam.paper.danxuan_count]
|
||||
multiple_qs = Question.objects.filter(Q(type="多选") & Q(questioncat__in=cqs)).order_by('?')[:exam.paper.duoxuan_count]
|
||||
judge_qs = Question.objects.filter(Q(type="判断") & Q(questioncat__in=cqs)).order_by('?')[:exam.paper.panduan_count]
|
||||
pqs = single_qs | multiple_qs | judge_qs
|
||||
for i in pqs:
|
||||
if i.type == '单选':
|
||||
total_score = exam.paper.danxuan_score
|
||||
elif i.type == '多选':
|
||||
total_score = exam.paper.duoxuan_score
|
||||
else:
|
||||
total_score = exam.paper.panduan_score
|
||||
details.append(AnswerDetail(examrecord=er, question=i, total_score=total_score))
|
||||
AnswerDetail.objects.bulk_create(details)
|
||||
ads = AnswerDetail.objects.select_related('question').filter(examrecord=er).order_by('id')
|
||||
ret['questions_'] = AnswerDetailOutSerializer(instance=ads, many=True).data
|
||||
|
|
Loading…
Reference in New Issue