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