Ejemplo n.º 1
0
Archivo: views.py Proyecto: YLAsce/oj
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)
    """
Ejemplo n.º 2
0
Archivo: views.py Proyecto: YLAsce/oj
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)
    """
Ejemplo n.º 3
0
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))
Ejemplo n.º 4
0
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), })
Ejemplo n.º 5
0
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)
    """