Exemplo n.º 1
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)
    """
Exemplo n.º 2
0
def submissionList(request, contest_id=None, page_id='1'):
    logger.info(str(request).replace("\n\r", "\t"))
    """
    @view: list submission of some contest
    """

    try:
        page_id = int(page_id)
        u = User.getSessionUser(request.session)
        if not u:
            raise Err(request, err='not login')

        cid = int(contest_id)

        try:
            c = Contest.getById(cid)
        except:
            raise Err(
                request,
                err='no contest',
                log_format=('{0}'.format(cid), ''),
                user_format=(u'{0}'.format(cid), u'别做坏事!'),
            )

        c.course_class_name = unicode(c.course_class.getFullName())
        c.description = unicode(c.contest_description)
        c.title = unicode(c.contest_title)
        now = datetime.now()
        if c.start_time + timedelta(minutes=c.length) < now:
            c.status = 'ended'
        elif c.start_time > now:
            c.status = 'scheduled'
        else:
            c.status = 'running'
        c.time_passed = min(
            max(int((now - c.start_time).total_seconds()) / 60, 0), c.length)
        c.time_passed_percent = 100 * c.time_passed / c.length
        c.time_left = c.length - c.time_passed

        isManager = c.course_class.canBeManaged(u)
        user = u if not isManager else None  # privilege for showing all submissions

        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'输入的内容不合法', ''))

        #sub_all_c = getSUB()
        #submissions = bigfilter( u=user, c=c, cp=contestProb, uname=form.cleaned_data['username'], lang=form.cleaned_data['language'], sta=form.cleaned_data['status'])
        submissions = Submission.submissionList(
            u=user,
            c=c,
            cp=contestProb,
            uname=form.cleaned_data['username'],
            lang=form.cleaned_data['language'],
            sta=form.cleaned_data['status'])

        submissions = Submission.submissionList(
            u=user,
            c=c,
            cp=contestProb,
            uname=form.cleaned_data['username'],
            lang=form.cleaned_data['language'],
            sta=form.cleaned_data['status'])
        if isManager and 'rejudge' in request.GET and c.board_type != 2:
            map(lambda x: Submission.rejudgeSubmission(x), submissions)

        paginator = Paginator(submissions, Const.STATUS_PER_PAGE)
        page_id = min(max(int(page_id), 1), paginator.num_pages)

        s = paginator.page(page_id)

        for sub_s in s:
            sub_s.status_color = Const.STATUS_COLOR[
                sub_s.status] if sub_s.status in Const.STATUS_COLOR else ''
            sub_s.status_cn = Const.STATUS_CN[sub_s.status]
        return render(
            request, 'newtpl/submission/status.html', {
                'sList': s,
                'form': form,
                'c': c,
                'tpl': {
                    'can_manage': True if isManager else False
                }
            })
        #return render(request, 'newtpl/submission/status.html', {'sList':s, 'form':form, 'c':c})

    except Exception as e:
        logger.error(str(e).replace("\n\r", "\t"))
        return render(request, Err.ERROR_PAGE, {'errmsg': unicode(e)})
Exemplo n.º 3
0
Arquivo: views.py Projeto: YLAsce/oj
def submissionList(request, contest_id=None, page_id='1'):
    logger.info(str(request).replace("\n\r","\t"))
    """
    @view: list submission of some contest
    """

    try:
        page_id = int(page_id)
        u = User.getSessionUser(request.session)
        if not u:
            raise Err( request, err='not login')

        cid = int(contest_id)

        try:
            c = Contest.getById(cid)
        except:
            raise Err( request, err='no contest', 
                    log_format=( '{0}'.format(cid), ''), 
                    user_format=( u'{0}'.format( cid), u'别做坏事!'),
                    )

        c.course_class_name = unicode(c.course_class.getFullName())
        c.description = unicode(c.contest_description)
        c.title = unicode(c.contest_title)
        now = datetime.now()
        if c.start_time+timedelta(minutes=c.length) < now:
            c.status = 'ended'
        elif c.start_time > now:
            c.status = 'scheduled'
        else:
            c.status = 'running'
        c.time_passed = min(max(int((now-c.start_time).total_seconds())/60, 0), c.length)
        c.time_passed_percent = 100*c.time_passed/c.length
        c.time_left = c.length-c.time_passed

        isManager = c.course_class.canBeManaged(u)
        user = u if not isManager else None # privilege for showing all submissions

        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'输入的内容不合法', '')
                    )

        submissions = Submission.submissionList( u=user, c=c, cp=contestProb, uname=form.cleaned_data['username'], lang=form.cleaned_data['language'], sta=form.cleaned_data['status'])

        if isManager and 'rejudge' in request.GET:
            map( lambda x: Submission.rejudgeSubmission( x), submissions)

        paginator = Paginator(submissions, Const.STATUS_PER_PAGE)
        page_id = min(max(int(page_id), 1), paginator.num_pages)

        s = paginator.page(page_id)

        for sub_s in s:
            sub_s.status_color = Const.STATUS_COLOR[sub_s.status] if sub_s.status in Const.STATUS_COLOR else ''
            sub_s.status_cn = Const.STATUS_CN[ sub_s.status]

        return render(request, 'newtpl/submission/status.html', {'sList':s, 'form':form, 'c':c, 'tpl':{'can_manage': True if isManager else False}})

    except Exception as e:
        logger.error(str(e).replace("\n\r","\t"))
        return render(request, Err.ERROR_PAGE, { 'errmsg': unicode(e) } )