diff --git a/safesite/exportemp/ks.docx b/safesite/exportemp/ks.docx index b3aed00a..d23d2c47 100644 Binary files a/safesite/exportemp/ks.docx and b/safesite/exportemp/ks.docx differ diff --git a/safesite/models.py b/safesite/models.py index ab2e52c2..60da73a1 100644 --- a/safesite/models.py +++ b/safesite/models.py @@ -764,13 +764,14 @@ class ExamTest(models.Model): # 考试表 createuser = models.ForeignKey( User, blank=True, null=True, on_delete=models.CASCADE, related_name='kscjr') qrcode = models.CharField(max_length=200, blank=True, null=True) - retest_count = models.IntegerField('允许重考次数', default=10) + testnum = models.IntegerField('考试机会', default=10) class ExamTestDetail(models.Model): # 考试详情表 id = models.AutoField(primary_key=True) testnum = models.IntegerField(default=0) # 做卷次数 + remainnum = models.IntegerField('剩余次数', default=1) examtest = models.ForeignKey( ExamTest, on_delete=models.CASCADE, null=True, blank=True) user = models.ForeignKey(User, on_delete=models.CASCADE) @@ -778,7 +779,6 @@ class ExamTestDetail(models.Model): # 考试详情表 endtime = models.DateTimeField(null=True, blank=True) took = models.IntegerField(default=0) # 耗时 rights = models.IntegerField(default=1) # 正确数 - ison = models.IntegerField(default=0) # 可参加0/已参加1/ passcode = models.IntegerField(default=0) # 是否通过 testdetail = JSONField(null=True, blank=True) score = models.FloatField(default=0) # 得分 diff --git a/safesite/templates/examtestadd.html b/safesite/templates/examtestadd.html index 9ef92300..8645a8cf 100644 --- a/safesite/templates/examtestadd.html +++ b/safesite/templates/examtestadd.html @@ -35,6 +35,10 @@ +
+ +
diff --git a/safesite/templates/examtestadd2.html b/safesite/templates/examtestadd2.html index abba88c8..fe267371 100644 --- a/safesite/templates/examtestadd2.html +++ b/safesite/templates/examtestadd2.html @@ -41,6 +41,10 @@
+
+ +
diff --git a/safesite/templates/examtestdetail.html b/safesite/templates/examtestdetail.html index ea617e52..67c0fe3a 100644 --- a/safesite/templates/examtestdetail.html +++ b/safesite/templates/examtestdetail.html @@ -85,6 +85,9 @@ 用时(s) + + 考试次数 + 答题详情 @@ -99,18 +102,25 @@ {{$value.id}} {{$value.user__name}} {{$value.user__ubelongpart__partname}} - {{if $value.ison==0}} - 可参加 - {{else}} - 已参加 - {{/if}} + + {{if $value.testnum > 0}} + 已考 + {{else}} + 未考 + {{/if}} + + {{if $value.remainnum > 0 && state==1}} + -可考 + {{/if}} + + {{$value.score}} {{$value.starttime}} {{$value.took}} - + {{$value.testnum}} 点击查看 - {{if $value.passcode==0&&$value.ison==1&&state==1}} - + {{if $value.passcode==0&&$value.remainnum==0&&state==1}} + {{else}} {{/if}} @@ -168,12 +178,11 @@ async: false, // ajax同步使用false success: function (data) { var cjrydetail = data.cjrydetail - console.log(cjrydetail) data['yingkrs'] = cjrydetail.length //应考人数 var x = 0 var y = 0 for(var i=0;i0){ x = x +1 if(cjrydetail[i].passcode==1){ y = y +1 diff --git a/safesite/views.py b/safesite/views.py index e6119923..24758a8f 100644 --- a/safesite/views.py +++ b/safesite/views.py @@ -5018,70 +5018,6 @@ def apitool(req): if created: print(i.partname + '建立默认地图') return JsonResponse({"code":1}) - elif a == 'panjuan': - test = ExamTest.objects.get(id=req.GET.get('test')) - answers = ExamPaperDetail.objects.filter(exampaper=test.exampaper).values('id', 'question__right') - answersdict = {} - for i in answers: - answersdict['paperdetail' + str(i['id'])] = i['question__right'] - panjuanlist = ExamTestDetail.objects.filter(examtest=test) - num = 0 - for obj in panjuanlist: - tms = [] - wrongs = [] - rights = 0 - testdetail = obj.testdetail - if testdetail: - score = 0 - 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']: - if set(i['userchecked']) == set(i['question__right']): - iscore = i['score'] - rights = rights + 1 - else: - miniscore = i['score']/len(i['question__right']) - wrongs.append(str(i['question__id'])) - for x in i['userchecked']: - if x in i['question__right']: - iscore = iscore + miniscore - else: - iscore = 0 - break - else: - if 'userchecked' in i: - if i['userchecked']: - if i['userchecked'] == i['question__right']: - iscore = i['score'] - rights = rights + 1 - else: - wrongs.append(str(i['question__id'])) - i['iscore'] = iscore - score = score + iscore - tms.append(str(i['question__id'])) - obj.testdetail = testdetail - obj.rights = rights - score = round(score,1) - obj.score = score - obj.ison = 1 - totalscore = test.totalscore - passscore = test.passscore - if score >= passscore: - passcode = 1 - else: - passcode = 0 - obj.passcode = passcode - if tms: - obj.tms = ','+','.join(tms)+',' - if wrongs: - obj.wrongs = ','+','.join(wrongs)+',' - obj.save() - num = num + 1 - print(str(num) + obj.examtest.name + obj.user.name + '得分' + str(score)) - return JsonResponse({"code":1}) elif a == 'correct_tzzs': updateTzzs() return JsonResponse({"code":1}) @@ -6176,7 +6112,7 @@ def apiexamtest(req): if state == 'close': a = a.filter(state=0) if owner == 'yes': - ownerlist = ExamTestDetail.objects.filter(user__userid=userid, examtest__state=1,ison=0).values_list('examtest__id',flat=True) + ownerlist = ExamTestDetail.objects.filter(user__userid=userid, examtest__state=1,testnum=0).values_list('examtest__id',flat=True) a = a.filter(Q(id__in=ownerlist)|Q(ispublic=1)) a = a.order_by('-id') total = a.count() @@ -6222,8 +6158,8 @@ def apiexamtest(req): obj.passscore = data['passscore'] obj.duration = data['duration'] obj.createuser = User.objects.get(userid=userid) - if 'retest_count' in data and data['retest_count']: - obj.retest_count = data['retest_count'] + if 'testnum' in data and data['testnum']: + obj.testnum = data['testnum'] obj.save() obj.qrcode = makeqr_examtest( 'https://safeyun.ctcshe.com/miniprogram/examtest?id='+str(obj.id)) @@ -6233,7 +6169,7 @@ def apiexamtest(req): b = [] for i in ksry: uobj = User.objects.get(userid=i) - ExamTestDetail.objects.create(examtest=obj, user=uobj) + ExamTestDetail.objects.create(examtest=obj, user=uobj, remainnum = obj.testnum) b.append(uobj.openid) postdict = { 'touser': '', @@ -6319,8 +6255,8 @@ def apiexamtest(req): obj.ispublic = 1 else: obj.ispublic = 0 - if 'retest_count' in data and data['retest_count']: - obj.retest_count = data['retest_count'] + if 'testnum' in data and data['testnum']: + obj.testnum = data['testnum'] obj.save() obj.qrcode = makeqr_examtest( 'https://safeyun.ctcshe.com/miniprogram/examtest?id='+str(obj.id)) @@ -6330,7 +6266,7 @@ def apiexamtest(req): b = [] for i in ksry: uobj = User.objects.get(userid=i) - ExamTestDetail.objects.create(examtest=obj, user=uobj) + ExamTestDetail.objects.create(examtest=obj, user=uobj, remainnum = obj.testnum) b.append(uobj.openid) postdict = { 'touser': '', @@ -6379,36 +6315,36 @@ def apiexamtest(req): elif a == 'detail2': id = req.GET.get('id') a = ExamTest.objects.filter(id=id).values('id', 'num', 'name', 'starttime', 'endtime', 'duration', 'totalscore', - 'passscore', 'exampaper__total', 'createtime', 'state', 'exampaper__name', 'createuser__name', 'type', 'qrcode', 'retest_count')[0] + 'passscore', 'exampaper__total', 'createtime', 'state', 'exampaper__name', 'createuser__name', 'type', 'qrcode', 'testnum')[0] a['notinTime'] = 0 if a['starttime'] > datetime.now(): a['notinTime'] = 1 if 'endtime' in a and a['endtime'] < datetime.now(): a['notinTime'] = 1 objs = ExamTestDetail.objects.filter(examtest__id=id).order_by('-score','-took').values( - 'id', 'user__name', 'user__ubelongpart__partname', 'took', 'score', 'ison', 'passcode','starttime', 'testnum') + 'id', 'user__name', 'user__ubelongpart__partname', 'took', 'score', 'remainnum', 'passcode','starttime', 'testnum') a['cjrydetail'] = list(objs) - a['ison'] = 0 + a['remainnum'] = 0 a['testnum'] = 0 queryset = ExamTestDetail.objects.filter(examtest__id=id,user__userid=userid) if queryset.exists(): - a['ison'] = queryset[0].ison + a['remainnum'] = queryset[0].remainnum a['testnum'] = queryset[0].testnum return HttpResponse(json.dumps(a, cls=MyEncoder), content_type="application/json") elif a == 'detail': id = req.GET.get('id') a = ExamTest.objects.filter(id=id).values('id', 'num', 'name', 'starttime', 'endtime', 'duration', 'totalscore', - 'passscore', 'exampaper__total', 'createtime', 'state', 'exampaper__name', 'createuser__name', 'type', 'qrcode', 'retest_count')[0] + 'passscore', 'exampaper__total', 'createtime', 'state', 'exampaper__name', 'createuser__name', 'type', 'qrcode', 'testnum')[0] a['notinTime'] = 0 if a['starttime'] > datetime.now(): a['notinTime'] = 1 if 'endtime' in a and a['endtime'] < datetime.now(): a['notinTime'] = 1 - a['ison'] = 0 + a['remainnum'] = 0 a['testnum'] = 0 queryset = ExamTestDetail.objects.filter(examtest__id=id,user__userid=userid) if queryset.exists(): - a['ison'] = queryset[0].ison + a['remainnum'] = queryset[0].remainnum a['testnum'] = queryset[0].testnum return HttpResponse(json.dumps(a, cls=MyEncoder), content_type="application/json") elif a == 'detailtm': @@ -6427,7 +6363,7 @@ def apiexamtest(req): a = ExamTest.objects a = a.filter(usecomps__contains=','+companyid + #未关闭的考试 ',').exclude(nousecomps__contains=','+companyid+',').filter(state=1,endtime__gte=datetime.now()) - ownerlist = ExamTestDetail.objects.filter(user__userid=userid, examtest__state=1,ison=0).values_list('examtest__id',flat=True) + ownerlist = ExamTestDetail.objects.filter(user__userid=userid, examtest__state=1,testnum=0).values_list('examtest__id',flat=True) dknum = a.filter(Q(id__in=ownerlist)|Q(ispublic=1)).count() return JsonResponse({"code":1, "dknum":dknum}) @@ -6439,14 +6375,13 @@ def apiexamtestdetail(req): companyid = getcompany(userid) if a == 'dknum': a = ExamTestDetail.objects - a = a.filter(user__userid=userid, examtest__state=1, - ison=0, examtest__endtime__gte=datetime.now()) + a = a.filter(user__userid=userid, examtest__state=1, testnum=0 , examtest__endtime__gte=datetime.now()) dknum = a.count() return JsonResponse({"code": 1, "dknum": dknum}) elif a == 'listdk': a = ExamTestDetail.objects a = a.filter(user__userid=userid, examtest__state=1, - ison=0).order_by('-id') + testnum=0).order_by('-id') total = a.count() startnum, endnum = fenye(req) a = a[startnum:endnum].values('id', 'examtest__id', 'examtest__name', 'examtest__starttime', @@ -6462,23 +6397,22 @@ def apiexamtestdetail(req): return HttpResponse(transjson(total, a), content_type="application/json") elif a == 'listyk': a = ExamTestDetail.objects - a = a.filter(user__userid=userid).exclude(ison=0) + a = a.filter(user__userid=userid).exclude(testnum=0) total = a.count() startnum, endnum = fenye(req) a = a.order_by('-starttime')[startnum:endnum].values('id', 'examtest__id', 'examtest__name', 'starttime', 'examtest__passscore', - 'examtest__state', 'ison', 'examtest__duration', 'took', 'score', 'passcode') + 'examtest__state', 'testnum', 'examtest__duration', 'took', 'score', 'passcode', 'remainnum') return HttpResponse(transjson(total, a), content_type="application/json") elif a == 'handtest': data = json.loads(req.body.decode('utf-8')) testid = data['testid'] 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)}) + defaults={'examtest': examtestobj,'user':User.objects.get(userid=userid), 'remainnum':examtestobj.testnum}) starttime = data['starttime'] endtime = datetime.now() took = (endtime - datetime.strptime(starttime, '%Y-%m-%d %H:%M:%S')).total_seconds() #计算相差多少秒 testdetail = data['sheet'] - obj.ison = 1 obj.testdetail = testdetail obj.save() score = 0 @@ -6519,6 +6453,7 @@ def apiexamtestdetail(req): score = score + iscore tms.append(str(i['question__id'])) obj.testnum = obj.testnum + 1 + obj.remainnum = obj.remainnum - 1 if obj.remainnum >= 1 else 0 obj.starttime = starttime obj.endtime = endtime obj.took = took @@ -6558,7 +6493,7 @@ def apiexamtestdetail(req): a = ExamTest.objects.get(id=id) if a.createuser==user: objss = ExamTestDetail.objects.get(id=examdlid) - objss.ison=0 + objss.remainnum= objss.remainnum + 1 objss.save() return JsonResponse({"code":1,"msg":"发布成功!"}) else: @@ -6593,14 +6528,14 @@ def apiexamtestrate(req): ''' companyid = req.GET.get('companyid') alltest = ExamTest.objects.filter(usecomps__contains=','+str(companyid)+',').exclude(nousecomps__contains=','+str(companyid)+',') - allexamtestdetail = ExamTestDetail.objects.filter(examtest__in=alltest,ison=1) + allexamtestdetail = ExamTestDetail.objects.filter(examtest__in=alltest,testnum__gte=1) objs = allexamtestdetail.values('user__userid','user__name','user__headimgurl','user__ubelongpart__partname').annotate(totalscore=Sum('score'),totaltook=Sum('took'),testnum=Count('user__userid')).order_by('-totalscore','totaltook') total = objs.count() objslist = list(objs) for i in objslist: i['rate'] = objslist.index(i) + 1 i['avgscore'] = round(i['totalscore']/i['testnum'],1) - orgsCal = allexamtestdetail.filter(score__gt=0,ison__gt=0).values('user__ubelongpart__partid','user__ubelongpart__partname').annotate(totaltest=Count('user__ubelongpart__partid'),avgscore=Avg('score')).order_by('-totaltest','-avgscore') + orgsCal = allexamtestdetail.filter(score__gt=0,testnum__gte=1).values('user__ubelongpart__partid','user__ubelongpart__partname').annotate(totaltest=Count('user__ubelongpart__partid'),avgscore=Avg('score')).order_by('-totaltest','-avgscore') allattenduser = allexamtestdetail.values_list('user__userid', flat=True) orgsCallist = list(orgsCal) for i in orgsCallist: