|
@@ -39,13 +39,48 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
'status':al.status,
|
|
|
}
|
|
|
answer_log.append(item)
|
|
|
+ ranks = []
|
|
|
+ rank_data = ExamLog.objects.filter(exam=instance.exam).order_by('rank').values('user__name','scores','rank')
|
|
|
+ for rank in rank_data:
|
|
|
+ item = {
|
|
|
+ 'name':rank['user__name'],
|
|
|
+ 'scores':rank['scores'],
|
|
|
+ 'rank':rank['rank'],
|
|
|
+ }
|
|
|
+ ranks.append(item)
|
|
|
result = {
|
|
|
'question': serializer.data,
|
|
|
'answer_log': answer_log,
|
|
|
- 'ranks': [],
|
|
|
+ 'ranks': ranks,
|
|
|
}
|
|
|
return response_ok(result)
|
|
|
|
|
|
+ @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,
|
|
|
+ exam__exam_time__lte=start_time,
|
|
|
+ user=request.user,
|
|
|
+ exam__exam_end_time__gte=timezone.now()
|
|
|
+ )
|
|
|
+ data = []
|
|
|
+ for exam_log in queryset:
|
|
|
+ if exam_log.exam.exam_time < timezone.now() < exam_log.exam.exam_end_time:
|
|
|
+ name = '您有一个考试,正在进行中,点击这里立即参加!'
|
|
|
+ id = exam_log.id
|
|
|
+ else:
|
|
|
+ time = (exam_log.exam.exam_time - timezone.now()).seconds
|
|
|
+ name = '您有一个考试,将在{}分钟后开始,请做好准备!'.format(int(time/60) + 1)
|
|
|
+ id = ''
|
|
|
+ item = {
|
|
|
+ 'id':id,
|
|
|
+ 'name':name,
|
|
|
+ 'exam_end_time':exam_log.exam.exam_end_time,
|
|
|
+ }
|
|
|
+ data.append(item)
|
|
|
+ return response_ok(data)
|
|
|
+
|
|
|
@action(methods=['get'], detail=False)
|
|
|
def get_exam(self, request):
|
|
|
start_time = timezone.now() + datetime.timedelta(minutes=30)
|
|
@@ -77,6 +112,20 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
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 timezone.now() < instance.exam.exam_time:
|
|
|
+ raise CustomError('还未到考试时间,请稍等!')
|
|
|
+ if timezone.now() > instance.exam.exam_end_time:
|
|
|
+ raise CustomError('考试已结束,禁止答题!')
|
|
|
# 点击下一题,保存
|
|
|
if now_practise:
|
|
|
detail = ExamPaperDetail.objects.filter(id=now_practise).first()
|
|
@@ -175,7 +224,7 @@ 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)
|
|
|
+ answer_log = ExamAnswerLog.objects.filter(main=instance, detail=single).exclude(status=ExamAnswerLog.NOTDONE)
|
|
|
single_questions_list.append(
|
|
|
{
|
|
|
'question_id': single,
|
|
@@ -185,7 +234,7 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
# 多选题
|
|
|
multiple_questions_list = []
|
|
|
for multiple in questions.filter(question__type=ExamQuestion.MULTIPLE):
|
|
|
- answer_log = ExamAnswerLog.objects.filter(main=instance, detail=multiple)
|
|
|
+ answer_log = ExamAnswerLog.objects.filter(main=instance, detail=multiple).exclude(status=ExamAnswerLog.NOTDONE)
|
|
|
multiple_questions_list.append(
|
|
|
{
|
|
|
'question_id': multiple,
|
|
@@ -195,7 +244,7 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
# 填空题
|
|
|
fill_questions_list = []
|
|
|
for fill in questions.filter(question__type=ExamQuestion.FILL):
|
|
|
- answer_log = ExamAnswerLog.objects.filter(main=instance, detail=fill)
|
|
|
+ answer_log = ExamAnswerLog.objects.filter(main=instance, detail=fill).exclude(status=ExamAnswerLog.NOTDONE)
|
|
|
fill_questions_list.append(
|
|
|
{
|
|
|
'question_id': fill,
|
|
@@ -205,7 +254,7 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
# 判断题
|
|
|
judgment_questions_list = []
|
|
|
for judgment in questions.filter(question__type=ExamQuestion.JUDGMENT):
|
|
|
- answer_log = ExamAnswerLog.objects.filter(main=instance, detail=judgment)
|
|
|
+ answer_log = ExamAnswerLog.objects.filter(main=instance, detail=judgment).exclude(status=ExamAnswerLog.NOTDONE)
|
|
|
judgment_questions_list.append(
|
|
|
{
|
|
|
'question_id': judgment,
|
|
@@ -231,7 +280,8 @@ class ExamLogViewSet(CustomModelViewSet):
|
|
|
# 习题交卷,把上个接口的判断答案,放到此处
|
|
|
try:
|
|
|
instance = self.get_object()
|
|
|
-
|
|
|
+ # if timezone.now() > instance.exam.exam_end_time:
|
|
|
+ # raise CustomError('考试已结束,禁止答题!')
|
|
|
with transaction.atomic():
|
|
|
paper_details = ExamPaperDetail.objects.filter(main=instance.exampaper, delete=False)
|
|
|
for detail in paper_details:
|