def judge_zhuguan(request): postjson = jh.post2json(request) action = postjson['action'] paperid = postjson['paperid'] ph = PaperHelper() ret = {'code': 404, 'info': 'unknown action ' + action} if action == 'getans': stuid = postjson['stuid'] student = TestRecord.objects.get(Q(stuid=stuid) & Q(paperid=paperid)) zhuguan = ph.GetZhuguan(json.loads(student.answers)) judge = {} has_judge = 0 if student.zhuguan_grade != -1: judge = student.zhuguan_detail judge = json.loads(judge) has_judge = 1 # print(zhuguan) ret = {'code': 200, 'count': zhuguan['count'], 'list': zhuguan['zhuguan_list'], 'has_judge': has_judge, 'judge': judge, 'confirmed': student.confirmed} pass elif action == 'submit': stuid = postjson['stuid'] record = TestRecord.objects.get(Q(stuid=stuid) & Q(paperid=paperid) & Q(confirmed='no')) record.zhuguan_grade = json.dumps(postjson['score']) record.zhuguan_detail = json.dumps(postjson['detail']) record.save() ret = {'code': 200, 'info': 'ok'} pass elif action == 'clean_zhuguan': answerlist = TestRecord.objects.filter(Q(paperid=paperid) & Q(confirmed='no')).update(zhuguan_grade=-1, zhuguan_detail="") ret = {'code': 200, 'info': 'ok'} pass elif action == 'getpro': paper = Paper.objects.get(pid=paperid) pro = ph.GetProb(json.loads(paper.prolist)['question_list'], postjson['proid']) ret = {'code': 200, 'problem': pro['problem'], 'right': pro['right']} pass elif action == 'nextid': records = TestRecord.objects.filter(Q(paperid=paperid) & Q(zhuguan_grade=-1) & Q(confirmed='no')) if records.count() == 0: ret = {'code': 201, 'info': 'no next student is found'} else: ret = {'code': 200, 'nextid': records[0].stuid} pass return HttpResponse(json.dumps(ret), content_type="application/json")
def judge_zhuguan(request): postjson = jh.post2json(request) action = postjson['action'] paperid = postjson['paperid'] ph = PaperHelper() ret = {'code': 404, 'info': 'unknown action ' + action} if action == 'getans': stuid = postjson['stuid'] student = TestRecord.objects.get(Q(stuid=stuid) & Q(paperid=paperid)) zhuguan = ph.GetZhuguan(json.loads(student.answers)) #print(zhuguan) ret = { 'code': 200, 'count': zhuguan['count'], 'list': zhuguan['zhuguan_list'] } pass elif action == 'submit': stuid = postjson['stuid'] record = TestRecord.objects.get(Q(stuid=stuid) & Q(paperid=paperid)) record.zhuguan_grade = json.dumps(postjson['zhuguan_score']) record.zhuguan_detail = json.dumps(postjson['zhuguan_detail']) record.save() ret = {'code': 200, 'info': 'ok'} pass elif action == 'clean_zhuguan': answerlist = TestRecord.objects.filter(paperid=paperid) for var in answerlist: #print(var.answers) record = TestRecord.objects.get( Q(stuid=var.stuid) & Q(paperid=paperid)) record.zhuguan_grade = -1 record.zhuguan_detail = "" record.save() ret = {'code': 200, 'info': 'ok'} pass return HttpResponse(json.dumps(ret), content_type="application/json")