|
@@ -40,7 +40,7 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
}
|
|
|
answer_log.append(item)
|
|
|
ranks = []
|
|
|
- rank_data = ExamLog.objects.filter(exam=instance.exam).order_by('rank').values('user__name','scores','rank')
|
|
|
+ rank_data = ExamLog.objects.filter(exam=instance.exam, rank__isnull=False, delete=False).order_by('rank').values('user__name','scores','rank')
|
|
|
for rank in rank_data:
|
|
|
item = {
|
|
|
'name':rank['user__name'],
|
|
@@ -57,6 +57,7 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
|
|
|
@action(methods=['get'], detail=False)
|
|
|
def get_home_exam(self, request):
|
|
|
+ # 首页,考试提示
|
|
|
start_time = timezone.now() + datetime.timedelta(minutes=30)
|
|
|
queryset = ExamLog.objects.filter(delete=False,
|
|
|
type=ExamLog.FORMAL,
|
|
@@ -83,6 +84,7 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
|
|
|
@action(methods=['get'], detail=False)
|
|
|
def get_exam(self, request):
|
|
|
+ # 正式考试,获取考试列表,提前半小时
|
|
|
start_time = timezone.now() + datetime.timedelta(minutes=30)
|
|
|
queryset = ExamLog.objects.filter(delete=False,
|
|
|
type=ExamLog.FORMAL,
|
|
@@ -99,6 +101,7 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
'exam_time':strftime(exam_log.exam.exam_time),
|
|
|
'exam_end_time':strftime(exam_log.exam.exam_end_time),
|
|
|
'duration':exam_log.exam.duration,
|
|
|
+ 'submit_time':exam_log.submit_time and True or False,
|
|
|
}
|
|
|
data.append(item)
|
|
|
return response_ok(data)
|
|
@@ -108,23 +111,16 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
now_practise = request.data.get('now_practise') # 当前提交的模拟考试明细id。第一题或继续答题时,该参数为空
|
|
|
answers = json.loads(request.data.get('answers')) # 答案, 第一题或继续答题时,该参数为空
|
|
|
next_practise = request.data.get('next_practise') # 下一题id,首次加载第一题,传空
|
|
|
+ submit = request.data.get('submit') # 交卷1,下一题为空
|
|
|
|
|
|
try:
|
|
|
with transaction.atomic():
|
|
|
instance = self.get_object()
|
|
|
- # d1 = datetime.datetime.strptime(str(timezone.now().strftime('%Y-%m-%d %H:%M:%S')), '%Y-%m-%d %H:%M:%S')
|
|
|
- # d2 = datetime.datetime.strptime(str(instance.exam.exam_time), '%Y-%m-%d %H:%M:%S')
|
|
|
- # d3 = datetime.datetime.strptime(str(instance.exam.exam_end_time), '%Y-%m-%d %H:%M:%S')
|
|
|
- # print(4444444444,(d1-d2).seconds)
|
|
|
- # print(555555555,(d1-d3).seconds)
|
|
|
- # exam_time = timezone.now() - instance.exam.exam_time
|
|
|
- # exam_end_time = timezone.now() - instance.exam.exam_end_time
|
|
|
- # print(33333333, timezone.now())
|
|
|
- # print(1111111111,instance.exam.exam_time, exam_time.seconds)
|
|
|
- # print(22222222,instance.exam.exam_end_time, exam_end_time.seconds)
|
|
|
+ if instance.submit_time:
|
|
|
+ raise CustomError('您已交卷,禁止重复答题!')
|
|
|
if timezone.now() < instance.exam.exam_time:
|
|
|
raise CustomError('还未到考试时间,请稍等!')
|
|
|
- if timezone.now() > instance.exam.exam_end_time:
|
|
|
+ if not submit and timezone.now() > instance.exam.exam_end_time:
|
|
|
raise CustomError('考试已结束,禁止答题!')
|
|
|
# 点击下一题,保存
|
|
|
if now_practise:
|
|
@@ -224,31 +220,31 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
flat=True)
|
|
|
single_questions_list = []
|
|
|
for single in questions.filter(question__type=ExamQuestion.SINGLE):
|
|
|
- answer_log = ExamAnswerLog.objects.filter(main=instance, detail=single).exclude(status=ExamAnswerLog.NOTDONE)
|
|
|
+ answers = ExamAnswerOptionLog.objects.filter(main__main=instance, main__detail=single).first()
|
|
|
single_questions_list.append(
|
|
|
{
|
|
|
'question_id': single,
|
|
|
- 'complete': answer_log and True or False,
|
|
|
+ 'complete': answers and True or False,
|
|
|
}
|
|
|
)
|
|
|
# 多选题
|
|
|
multiple_questions_list = []
|
|
|
for multiple in questions.filter(question__type=ExamQuestion.MULTIPLE):
|
|
|
- answer_log = ExamAnswerLog.objects.filter(main=instance, detail=multiple).exclude(status=ExamAnswerLog.NOTDONE)
|
|
|
+ answers = ExamAnswerOptionLog.objects.filter(main__main=instance, main__detail=multiple).first()
|
|
|
multiple_questions_list.append(
|
|
|
{
|
|
|
'question_id': multiple,
|
|
|
- 'complete': answer_log and True or False,
|
|
|
+ 'complete': answers and True or False,
|
|
|
}
|
|
|
)
|
|
|
# 填空题
|
|
|
fill_questions_list = []
|
|
|
for fill in questions.filter(question__type=ExamQuestion.FILL):
|
|
|
- answer_log = ExamAnswerLog.objects.filter(main=instance, detail=fill).exclude(status=ExamAnswerLog.NOTDONE)
|
|
|
+ answers = ExamAnswerFillLog.objects.filter(main__main=instance, main__detail=multiple).first()
|
|
|
fill_questions_list.append(
|
|
|
{
|
|
|
'question_id': fill,
|
|
|
- 'complete': answer_log and True or False,
|
|
|
+ 'complete': answers and True or False,
|
|
|
}
|
|
|
)
|
|
|
# 判断题
|
|
@@ -280,8 +276,10 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
# 习题交卷,把上个接口的判断答案,放到此处
|
|
|
try:
|
|
|
instance = self.get_object()
|
|
|
- # if timezone.now() > instance.exam.exam_end_time:
|
|
|
- # raise CustomError('考试已结束,禁止答题!')
|
|
|
+ if timezone.now() > instance.exam.exam_end_time:
|
|
|
+ raise CustomError('考试已结束,禁止答题!')
|
|
|
+ if instance.submit_time:
|
|
|
+ raise CustomError('您已交卷,禁止重复交卷!')
|
|
|
with transaction.atomic():
|
|
|
paper_details = ExamPaperDetail.objects.filter(main=instance.exampaper, delete=False)
|
|
|
for detail in paper_details:
|