判卷优化

This commit is contained in:
caoqianming 2020-02-29 20:34:31 +08:00
parent fe44b5d492
commit 399a8bd32c
1 changed files with 17 additions and 8 deletions

View File

@ -6120,8 +6120,11 @@ def apiexamtest(req):
user = User.objects.get(userid=userid)
a = ExamTest.objects.get(id=id)
if user.issuper == 1 or a.createuser == user:
ExamTestDetail.objects.filter(examtest=a).delete()
a.delete()
nl = a.nousecomps.split(',')
nl.append(companyid)
nl = ','+','.join(list(filter(None, nl)))+','
a.nousecomps = nl
a.save()
return JsonResponse({"code": 1})
else:
return JsonResponse({"code": 0})
@ -6156,7 +6159,7 @@ def apiexamtest(req):
id = req.GET.get('id')
test = ExamTest.objects.get(id=id)
objs = ExamPaperDetail.objects.filter(exampaper=test.exampaper).order_by('question__type','?').values(
'id', 'question__id', 'score', 'question__title', 'question__type', 'question__answer', 'question__right', 'question__resolution')
'id', 'question__id', 'score', 'question__title', 'question__type', 'question__answer', 'question__resolution')
duration = test.duration
data = {'duration': duration, 'tms': list(objs), 'starttime':datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
return JsonResponse(data)
@ -6211,21 +6214,27 @@ def apiexamtestdetail(req):
elif a == 'handtest':
data = json.loads(req.body.decode('utf-8'))
testid = data['testid']
obj,created = ExamTestDetail.objects.get_or_create(examtest__id=testid, user__userid=userid,
defaults={'examtest': ExamTest.objects.get(id=testid),'user':User.objects.get(userid=userid)})
examtestobj = ExamTest.objects.get(id=testid)
obj,created = ExamTestDetail.objects.get_or_create(examtest = examtestobj, user__userid=userid,
defaults={'examtest': examtestobj,'user':User.objects.get(userid=userid)})
starttime = data['starttime']
endtime = datetime.now()
took = (endtime - datetime.strptime(starttime, '%Y-%m-%d %H:%M:%S')).total_seconds() #计算相差多少秒
if 'took' in data:
if data['took']<took:
took = data['took']
# if 'took' in data:
# if data['took']<took:
# took = data['took']
testdetail = data['sheet']
score = 0
rights = 0
tms = []
wrongs = []
answers = ExamPaperDetail.objects.filter(exampaper=examtestobj.exampaper).values('id', 'question__right')
answersdict = {}
for i in answers:
answersdict['paperdetail' + str(i['id'])] = i['question__right']
for i in testdetail: # 判卷
iscore = 0
i['question__right'] = answersdict['paperdetail'+str(i['id'])]
if i['question__type'] == 2:
if 'userchecked' in i:
if i['userchecked']: