def addRecord(request, cid): try: u = User.getSessionUser(request.session) if not u: raise Err(request, err='not login') c = Contest.getById(cid) try: c.canBeManaged(u) except: raise Err(request, err='no priv') cp = c.getContestProblem() if request.method == 'POST': form = ChooseProbForm(cp, request.POST) if form.is_valid(): Cheat.addRecord(cp_set=form.cleaned_data['contest_problem']) Cheat.antiCheat() return redirect('Cheat:show_cheat_result', cid=c.cid) else: raise Err(request, err='unknown err') else: form = ChooseProbForm(cp) return render(request, 'newtpl/cheat/addRecord.html', {'tpl':{'sp':True,}, 'contest':c, 'form':form,}) except Exception as e: return render(request, Err.ERROR_PAGE)
def addRecord(request): try: contestid = request.GET.get('contestid','-1') if contestid=='': return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) Cheat.addRecord(contestid) return render_to_response("Cheat/addComplete.html") except Exception as e: return render(request, Const.ERROR_PAGE, {'errmsg': unicode(e), }) #return render( request, 'error.html','errmsg'=str(e)) #def goBack(request): # return render_to_response("Cheat/antiCheat.html") def showResult(request): try: cheat_list = Cheat.getCheatList() cheat_user_list = [] for cl in cheat_list: cheat_user = [] cheat_user.append(cl.user1) cheat_user.append(cl.user2) cheat_user.append(cl.contest_problem) cheat_user.append(cl.ratio) cheat_user_list.append(cheat_user) return render_to_response("Cheat/showResult.html", {'cheat_list':cheat_user_list}) except Exception as e: return render( request, 'error.html','errmsg'=str(e))
def addRecord(request): try: contestid = request.GET.get('contestid','-1') if contestid=='': return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) Cheat.addRecord(contestid) return render_to_response("Cheat/addComplete.html") except Exception as e: return render(request, Const.ERROR_PAGE, {'errmsg': unicode(e), })
def addRecord(request): try: contestid = request.GET.get('contestid', '-1') if contestid == '': return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) Cheat.addRecord(contestid) return render_to_response("Cheat/addComplete.html") except Exception as e: return render(request, Const.ERROR_PAGE, { 'errmsg': unicode(e), })
def addRecord2(request, cid): try: u = User.getSessionUser(request.session) if not u: raise Err(request, err='not login') c = Contest.getById(cid) try: c.canBeManaged(u) except: raise Err(request, err='no priv') cp = c.getContestProblem() Cheat.addRecord(cp_set=cp) Cheat.antiCheat() return redirect('Cheat:show_cheat_result', cid=c.cid) except Exception as e: return render(request, Err.ERROR_PAGE)
def showResult(request, cid, page='1'): try: u = User.getSessionUser(request.session) if not u: raise Err(request, err='not login') c = Contest.getById(int(cid)) try: c.canBeManaged(u) except: raise Err(request, err='no priv') if ('threshold' in request.GET) and request.GET['threshold']: threshold = float(request.GET['threshold']) else: threshold = Const.CHEAT_DEFAULT_THRESHOLD cheatList = Cheat.getCheatList(contest=c, threshold=threshold) paginator = Paginator(cheatList, Const.CHEAT_PER_PAGE) page = min(max(int(page), 1), paginator.num_pages) cl = paginator.page(page) for idx, element in enumerate(cl): info_a = eval(element.sub1.other_info) info_b = eval(element.sub2.other_info) #cl[idx] = {'c': element, 'ip_a': info_a['submit_ip'], 'ip_b': info_b['submit_ip']} return render(request, 'newtpl/cheat/showResult.html', { 'tpl': { 'sp': True, }, 'contest': c, 'cheat_list': cl }) except Exception as e: return render(request, Err.ERROR_PAGE) # def codeDiff(request, ctid): # try: # u = User.getSessionUser(request.session) # if not u: # raise Err(request, err='not login') # ct = Cheat.objects.select_related('sub1__user', 'sub2__user').get(ctid=ctid) # # try: # ct.contest.canBeManaged(u) # except: # raise Err(request, err='no priv') # # return render(request, 'newtpl/cheat/codeDiff.html', {'tpl':{'sp':True,}, 'sub1':ct.sub1, 'sub2':ct.sub2}) # # # except Exception as e: # return render(request, Err.ERROR_PAGE) """
def showResult(request, cid, page='1'): try: u = User.getSessionUser(request.session) if not u: raise Err(request, err='not login') c = Contest.getById(int(cid)) try: c.canBeManaged(u) except: raise Err(request, err='no priv') if ('threshold' in request.GET) and request.GET['threshold']: threshold = float(request.GET['threshold']) else: threshold = Const.CHEAT_DEFAULT_THRESHOLD cheatList = Cheat.getCheatList(contest=c, threshold=threshold) paginator = Paginator(cheatList, Const.CHEAT_PER_PAGE) page = min(max(int(page), 1), paginator.num_pages) cl = paginator.page(page) ipa = [] ipb = [] for idx, element in enumerate(cl): info_a = eval(element.sub1.other_info) info_b = eval(element.sub2.other_info) #cl[idx] = {'c': element, 'ip_a': info_a['submit_ip'], 'ip_b': info_b['submit_ip']} ipa.append(info_a['submit_ip']) ipb.append(info_b['submit_ip']) return render(request, 'newtpl/cheat/showResult.html', {'tpl':{'sp':True,}, 'contest':c, 'cheat_list':cl, 'ipa':ipa,'ipb':ipb }) except Exception as e: return render(request, Err.ERROR_PAGE) # def codeDiff(request, ctid): # try: # u = User.getSessionUser(request.session) # if not u: # raise Err(request, err='not login') # ct = Cheat.objects.select_related('sub1__user', 'sub2__user').get(ctid=ctid) # # try: # ct.contest.canBeManaged(u) # except: # raise Err(request, err='no priv') # # return render(request, 'newtpl/cheat/codeDiff.html', {'tpl':{'sp':True,}, 'sub1':ct.sub1, 'sub2':ct.sub2}) # # # except Exception as e: # return render(request, Err.ERROR_PAGE) """
def showResult(request): try: cheat_list = Cheat.getCheatList() cheat_user_list = [] for cl in cheat_list: cheat_user = [] cheat_user.append(cl.user1) cheat_user.append(cl.user2) cheat_user.append(cl.contest_problem) cheat_user.append(cl.ratio) cheat_user_list.append(cheat_user) return render_to_response("Cheat/showResult.html", {'cheat_list':cheat_user_list}) except Exception as e: return render( request, 'error.html','errmsg'=str(e))
def showResult(request): try: cheat_list = Cheat.getCheatList() cheat_user_list = [] for cl in cheat_list: cheat_user = [] cheat_user.append(cl.user1) cheat_user.append(cl.user2) cheat_user.append(cl.contest_problem) cheat_user.append(cl.ratio) cheat_user_list.append(cheat_user) return render_to_response("Cheat/showResult.html", {'cheat_list':cheat_user_list}) except Exception as e: return render(request, Const.ERROR_PAGE, {'errmsg': unicode(e), })
def showResult(request, cid, page='1'): try: u = User.getSessionUser(request.session) if not u: raise Err(request, err='not login') c = Contest.getById(int(cid)) try: c.canBeManaged(u) except: raise Err(request, err='no priv') if ('threshold' in request.GET) and request.GET['threshold']: threshold = float(request.GET['threshold']) else: threshold = Const.CHEAT_DEFAULT_THRESHOLD #------------form------------- idxList = [(cp.problem_index, cp.problem_index) for cp in c.getContestProblem()] langList = [('gcc','GNU C'), ('g++','GNU C++'), ('java','java')] form = submissionListForm(idxList, langList, request.GET) if form.is_valid(): if form.cleaned_data['problem_index']: try: contestProb = ContestProblem.getBy( c, form.cleaned_data['problem_index']) except: contestProb=None # raise Exception(u'contest problem not found') else: contestProb=None else: raise Err( request, err='example err', log_format=( 'form invalid', ''), user_format=( u'输入的内容不合法', '') ) #------------form-------------- cheatList = Cheat.getCheatList(contest=c, threshold=0) #------------filter------------ if contestProb: cheatList = cheatList.filter(contest_problem=contestProb) if form.cleaned_data['username']: cheatList1 = cheatList.filter(sub1__user__username__icontains=form.cleaned_data['username']) cheatList2 = cheatList.filter(sub2__user__username__icontains=form.cleaned_data['username']) cheatList = cheatList1 | cheatList2 #------------filter------------ paginator = Paginator(cheatList, Const.CHEAT_PER_PAGE) page = min(max(int(page), 1), paginator.num_pages) cl = paginator.page(page) ipa = [] ipb = [] for idx, element in enumerate(cl): info_a = eval(element.sub1.other_info) info_b = eval(element.sub2.other_info) #cl[idx] = {'c': element, 'ip_a': info_a['submit_ip'], 'ip_b': info_b['submit_ip']} ipa.append(info_a['submit_ip']) ipb.append(info_b['submit_ip']) return render(request, 'newtpl/cheat/showResult.html', {'tpl':{'sp':True,}, 'contest':c, 'cheat_list':cl, 'ipa':ipa,'ipb':ipb, 'form':form }) except Exception as e: return render(request, Err.ERROR_PAGE) # def codeDiff(request, ctid): # try: # u = User.getSessionUser(request.session) # if not u: # raise Err(request, err='not login') # ct = Cheat.objects.select_related('sub1__user', 'sub2__user').get(ctid=ctid) # # try: # ct.contest.canBeManaged(u) # except: # raise Err(request, err='no priv') # # return render(request, 'newtpl/cheat/codeDiff.html', {'tpl':{'sp':True,}, 'sub1':ct.sub1, 'sub2':ct.sub2}) # # # except Exception as e: # return render(request, Err.ERROR_PAGE) """