예제 #1
0
def showCodeDiff(request, ct_id):
    """
    show codes of the two diffed submission
    """
    try:
        u = User.getSessionUser( request.session)
        if not u:
            raise Err( request, err='not login')

        ct_id = int( ct_id)
        ct = Cheat.objects.select_related('sub1__user', 'sub2__user').get(ctid=ct_id)

        # try:
        #     ct.contest.canBeManaged(u)
        # except:
        #     raise Err(request, err='no priv')

        s_a = ct.sub1
        s_b = ct.sub2
        #sid_a = int( sid_a)
        #sid_b = int( sid_b)

        #try:
        #    s_a = Submission.getById( sid_a)
        #except:
        #    raise Err( request, err='no submission',
        #            log_format=( '{0}'.format( sid_a), ''),
        #            user_format=( u'{0}'.format( sid_a), u'不要搞笑!!'),
        #            )

        #try:
        #    s_b = Submission.getById( sid_b)
        #except:
        #    raise Err( request, err='no submission',
        #            log_format=( '{0}'.format( sid_b), ''),
        #            user_format=( u'{0}'.format( sid_b), u'不要搞笑!!'),
        #            )

        if not Submission.canViewCode( s_a, u):
            raise Err( request, err = 'no priv')

        if not Submission.canViewCode( s_b, u):
            raise Err( request, err = 'no priv')

        info_a = eval( s_a.other_info)
        info_b = eval( s_b.other_info)

        ip_a = info_a['submit_ip']
        ip_b = info_b['submit_ip']

        brush_a = Const.BRUSH[s_a.code_language]
        brush_b = Const.BRUSH[s_b.code_language]

        # brush_a = s_a.code_language
        # brush_b = s_b.code_language

        # info['status_cn'] = Const.STATUS_CN[info['status']]
        #if 'case_result' in info:
        #    for seq in info['case_result']:
        #        seq['res_cn'] = JUDGE_RES_CN[seq['res']]

        return render( request, 'newtpl/cheat/code_diff.html', { 'ct_obj': ct, 'sub_a': s_a, 'sub_b': s_b, 'code_a': default_storage.open(s_a.code_file).read().decode('utf-8', 'ignore'), 'code_b': default_storage.open(s_b.code_file).read().decode('utf-8', 'ignore'), 'tpl': { 'sp': True },  'brush_a': brush_a, 'brush_b': brush_b, 'ip_a': ip_a, 'ip_b': ip_b})

    except Exception as e:
        return render( request, Err.ERROR_PAGE, { 'errmsg': unicode(e), }, )
예제 #2
0
def viewCodeAndInfo(request, sid):
    logger.info(str(request).replace("\n\r", "\t"))
    """
    view used to see details of the very submission
    """
    try:
        sid = int(sid)
        u = User.getSessionUser(request.session)
        if not u:
            raise Err(request, err='not login')

        try:
            s = Submission.getById(sid)
        except:
            raise Err(
                request,
                err='no submission',
                log_format=('{0}'.format(sid), ''),
                user_format=(u'{0}'.format(sid), u'不要搞笑!!'),
            )

        if not Submission.canViewCode(s, u):
            raise Err(request, err='no priv')

        info = eval(s.other_info)

        if 'ce' in info:
            info['ce'] = info['ce'].replace('/${TOKISAKI_KURUMI}', '')

        info['brush'] = Const.BRUSH[s.code_language]
        info['lang'] = Const.LANG_REFLECT[s.code_language]

        info['judger'] = Const.JUDGER_NAME
        info['user'] = s.user.uid
        info['judge_time'] = str(s.submission_time)
        info['status_cn'] = Const.STATUS_CN[info['status']]
        info['status_color'] = Const.STATUS_COLOR[
            info['status']] if info['status'] in Const.STATUS_COLOR else ''
        # info['submit_ip'] = request.META['REMOTE_ADDR']

        if 'score_sum' not in info:
            case_dict = json.loads(s.problem_index.problem.case_info)
            # score_sum = 0
            # for score in case_dict:
            # score_sum += int( score)
            score_sum = sum(map(int, case_dict.values()))
            info['score_sum'] = score_sum
            s.other_info = str(info)
            s.save()

        if 'case_result' in info:
            score_obtained = 0
            for seq in info['case_result']:
                seq['res_cn'] = JUDGE_RES_CN[seq['res']]
                temp_res = 'status-' + seq['res']
                seq['res_color'] = temp_res
                if 'score' in seq:
                    score_obtained += int(seq['score'])

            info['score_obtained'] = score_obtained

            # seq['res_color'] = Const.STATUS_COLOR[temp_res] if temp_res in Const.STATUS_COLOR else ''

        return render(
            request,
            'newtpl/submission/code_and_info.html',
            {
                'submission':
                s,
                'info':
                info,
                'code_content':
                default_storage.open(s.code_file).read().decode(
                    'utf-8', 'ignore'),
                'tpl': {
                    'sp': True
                },
            },
        )

    except Exception as e:
        logger.error(str(e).replace("\n\r", "\t"))
        return render(
            request,
            Err.ERROR_PAGE,
            {
                'errmsg': unicode(e),
            },
        )
예제 #3
0
파일: views.py 프로젝트: YLAsce/oj
def viewCodeAndInfo( request, sid):
    logger.info(str(request).replace("\n\r","\t"))
    """
    view used to see details of the very submission
    """
    try:
        sid = int( sid)
        u = User.getSessionUser( request.session)
        if not u:
            raise Err( request, err='not login')

        try:
            s = Submission.getById( sid)
        except:
            raise Err( request, err='no submission',
                    log_format=( '{0}'.format( sid), ''),
                    user_format=( u'{0}'.format( sid), u'不要搞笑!!'),
                    )

        if not Submission.canViewCode( s, u):
            raise Err( request, err = 'no priv')

        info = eval( s.other_info)
        
        if 'ce' in info:
            info['ce'] = info['ce'].replace('/${TOKISAKI_KURUMI}', '')

        info['brush'] = Const.BRUSH[s.code_language]
        info['lang'] = Const.LANG_REFLECT[s.code_language]

        info['judger'] = Const.JUDGER_NAME
        info['user'] = s.user.uid
        info['judge_time'] = str(s.submission_time)
        info['status_cn'] = Const.STATUS_CN[info['status']]
        info['status_color'] = Const.STATUS_COLOR[info['status']] if info['status'] in Const.STATUS_COLOR else ''
        # info['submit_ip'] = request.META['REMOTE_ADDR']

        if 'score_sum' not in info:
            case_dict = json.loads(s.problem_index.problem.case_info)
            # score_sum = 0
            # for score in case_dict:
                # score_sum += int( score)
            score_sum = sum( map( int, case_dict.values()))
            info['score_sum'] = score_sum
            s.other_info = str( info)
            s.save()

        if 'case_result' in info:
            score_obtained = 0
            for seq in info['case_result']:
                seq['res_cn'] = JUDGE_RES_CN[seq['res']]
                temp_res = 'status-' + seq['res']
                seq['res_color'] = temp_res
                if 'score' in seq:
                    score_obtained += int(seq['score'])

            info['score_obtained'] = score_obtained

                # seq['res_color'] = Const.STATUS_COLOR[temp_res] if temp_res in Const.STATUS_COLOR else ''

        return render( request, 'newtpl/submission/code_and_info.html', { 'submission': s, 'info': info, 'code_content': default_storage.open(s.code_file).read().decode('utf-8','ignore'), 'tpl': { 'sp': True },  }, )

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