当前位置: 首页>>代码示例>>Python>>正文


Python Contest.getById方法代码示例

本文整理汇总了Python中Contest.models.Contest.getById方法的典型用法代码示例。如果您正苦于以下问题:Python Contest.getById方法的具体用法?Python Contest.getById怎么用?Python Contest.getById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Contest.models.Contest的用法示例。


在下文中一共展示了Contest.getById方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: updateContestNotice

# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import getById [as 别名]
def updateContestNotice(request, cId, cnId):
    try:
        u = User.getSessionUser(request.session)
        if not u:
            raise Exception(Const.NOT_LOGGED_IN)
        
        c = Contest.getById(cId)
        cn = ContestNotice.getById(cnId)
        c.canBeManaged(u)
        
        if request.method == 'POST':
            form = contestNoticeForm(request.POST)
            if form.is_valid():
                cnTitle = form.cleaned_data['title']
                cnContent = form.cleaned_data['content']
                cn.updateNotice(cnTitle, cnContent)
                return redirect('Contest:show_contest_notice', cId, cn.id)
            else:
                return render(request, 'newtpl/contest/updateContestNotice.html',
                              {'form': form, 'cid': cId, 'cnid': cnId,
                           'tpl':{'has_priv': True, 'sp': True, 'nav_act':'contest',}})
        else:
            form = contestNoticeForm(
                initial={
                    'title': cn.notice_title,
                    'content': cn.notice_content,
                    }
            )
            return render(request, 'newtpl/contest/updateContestNotice.html',
                          {'form': form, 'cid': cId, 'cnid': cnId,
                           'tpl':{'has_priv': True, 'sp': True, 'nav_act':'contest',}})
    except Exception as e:
        return render(request, Const.ERROR_PAGE, {'errmsg': unicode(e), })
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:35,代码来源:views.py

示例2: viewAllClarifications

# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import getById [as 别名]
def viewAllClarifications(request, cid):
    logger.info(str(request).replace("\n","\t"))
    try:
        u = User.getSessionUser(request.session)
        if not u:
            raise Exception(Const.NOT_LOGGED_IN)
        c = Contest.getById(cid)
        if not c:
            raise Exception(Const.CONTEST_NOT_EXIST)
        
        cs = Clarification.getByContestId(cid)
        try:
            c.canEnterContest(u)
            can_add_clar = True
        except:
            can_add_clar = False

        try:
            c.canBeManaged(u)
            can_update_clar = True
        except:
            can_update_clar = False

        return render(request, 'newtpl/contest/viewAllClars.html', {'clars': cs, 'contest': c, 'can_add_clar': can_add_clar, 'can_update_clar': can_update_clar})
    except Exception as e:
        logger.error(unicode(e).replace('\n', '\t')) 
        return render(request, Err.ERROR_PAGE, {'errmsg': unicode(e)})    
开发者ID:YLAsce,项目名称:oj,代码行数:29,代码来源:views.py

示例3: addRecord

# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import getById [as 别名]
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)
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:29,代码来源:views.py

示例4: board

# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import getById [as 别名]
def board(request):
    cid = request.GET.get('cid', 1)
    contest = Contest.getById(cid)
    '''
    if contest == False :
        errmsg = u'不存在考试编号为' + str(cid) + u'的考试'
        return render(request, 'error.html', {'errmsg' : errmsg, 'user' : User.getSessionUser(request.session)})
    contestProblem = contest.getContestProblem()
    startTime = contest.start_time
    '''
    submission = Submission.submissionList(cid = cid)
    
    problemIndex = list()
    problemIndex.append('A')#
    problemIndex.append('B')#
    '''
    for i in contestProblem:
        problemIndex.append(i.problem_index)
    '''
    problemIndex.sort()
    
    data = dict()
    cnt = 0
    now = datetime.now()
    now = now - now
    for i in submission :
        if i.user.username not in data :
            data[i.user.username] = [cnt, i.user.username,  0, now] #id, username, solved, time, A, B, etc
            cnt = cnt + 1
            for j in problemIndex :
                data[i.user.username].append({'ac' : 0, 'pd' : 0, 'other' : 0})

        tmp = data[i.user.username]
        tp = tmp[i.problem_index.problem_index + 3]
        if tp['ac'] == 0 :
            if ('Accepted', 'Accepted') in i.status :
                tp['ac'] = 1
                tp['other'] = tp['other'] + 1
                tmp[3] += datetime.timedelta((tp['pd'] + tp['ac'] + tp['other']) * 20) + (i.submission_time - startTime)
                tmp[2] += 1
            elif ('Pending', 'Pending') in i.status :
                tp['pd'] = tp['tp'] + 1
            else :
                tp['other'] = tp['other'] + 1

    out = list()
    for i in data :
        out.append(data[i])
   
    out.append([0, 'zhangzhou', 12, -(datetime.now() - datetime.now()) , {'ac': 0, 'pd' : 2, 'other' : 0}, {'ac' : 0,'pd' : 0, 'other' : 0}])#
    out.append([-1, 'lyy', 12, -(datetime.now() - datetime.now()), {'ac': 1, 'pd' : 2, 'other' : 3}, {'ac': 0, 'pd' : 0, 'other' : 0}])#
    out.sort(cmp = mycmp)
    cnt = 1
    for i in out :
        i[0] = cnt
        cnt = cnt + 1
        i[3] = (datetime(2000, 1, 1, 0, 0, 0, 0) + i[3]).strftime("%H:%M:%S")

    return render(request, 'lyy/board.html', {'out' : out, 'problemIndex' : problemIndex, 'user' : User.getSessionUser(request.session)})
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:61,代码来源:views.py

示例5: releaseBoardTime

# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import getById [as 别名]
def releaseBoardTime(request, cId):
    try:
        u = User.getSessionUser(request.session)
        if not u:
            raise Exception(Const.NOT_LOGGED_IN)
        try:
            c = Contest.getById(cId)
        except:
            raise Err(request, 'no resource')
        try:
            c.canBeManaged(u)
        except:
            raise Err(request, err='no priv')

        c = Contest.getById(cId)
        c.board_stop = c.length
        c.save()
        return redirect('Contest:show_contest', cId)
    except Exception as e:
        return render(request, Const.ERROR_PAGE, {'errmsg': unicode(e), })
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:22,代码来源:views.py

示例6: showResult

# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import getById [as 别名]
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)
    """
开发者ID:YLAsce,项目名称:oj,代码行数:55,代码来源:views.py

示例7: showContestNotice

# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import getById [as 别名]
def showContestNotice(request, cId, cnId):
    try:
        u = User.getSessionUser(request.session)
        if not u:
            raise Exception(Const.NOT_LOGGED_IN)
        
        c = Contest.getById(cId)
        cn = ContestNotice.getById(cnId)
        c.canEnterContest(u)
        return render(request, 'newtpl/contest/showContestNotice.html',
                      {'cid': cId, 'contest_notice': cn,
                       'tpl': {'has_priv': Contest.hasPriv(c.course_class, u), 'sp': True, 'nav_act':'contest',}})
    except Exception as e:
        return render(request, Const.ERROR_PAGE, {'errmsg': unicode(e), })
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:16,代码来源:views.py

示例8: boardDetail

# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import getById [as 别名]
def boardDetail(request, cid):
    try:
        cdata = cache.get(make_key(cid, 'board'))
        if cdata:
            return JSONResponse(eval(zlib.decompress(cdata)))
        c = Contest.getById(cid)
        b = Board()
        b.contest = c
        if request.method == 'GET':
            serializer = BoardSerializer(b)
            data = serializer.data
            cache.set(make_key(cid, 'board'), zlib.compress(str(data)), 60)
            return JSONResponse(data)
    except Exception as e:
        return HttpResponse(e)
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:17,代码来源:views.py

示例9: addRecord2

# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import getById [as 别名]
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)
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:20,代码来源:views.py

示例10: showContestProblem

# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import getById [as 别名]
def showContestProblem(request,c_id,idx): # modified
    logger.info(str(request).replace("\n","\t"))
    try:
        u = User.getSessionUser(request.session)
        if not u:
            raise Err(request, 'not login')

        c_id = int(c_id)
        c = Contest.getById(c_id)
    	cn = c.getContestNotice()
        cp = ContestProblem.getBy(c=c, idx=idx)

        try:
            c.canEnterContest(u)
        except:
            raise Err(request, 'no priv')

        can_manage = True
        try:
            c.canBeManaged(u)
        except:
            can_manage = False

        if (not c.canEnterWithTime(u)) and (not can_manage):
            raise Err(request, 'contest not started')

        c.course_class_name = unicode(c.course_class.getFullName())

        p = cp.problem
        p.idx = cp.problem_index
        p.title = unicode(cp.problem_title)
        p.desc=json.loads(p.prob_desc)

        cp_list = c.getContestProblem()       
	for cp, cp_res, cp_user_res in zip(cp_list, getContestResult(c=c), getContestUserResult(c=c, u=u)):
            cp.ac = cp_res['ac_cnt']
            cp.sub = cp_res['sub_cnt']
            cp.user_res = cp_user_res

        return render(request, "newtpl/problem/showContestProblem.html", {'c':c, 'cp_list':cp_list,'contest_notice_list':cn, 'p':p, 'status_query':queryString(problem_index=p.idx), 'tpl':{'sp':True, 'can_manage':can_manage}}) 
    except Exception as e:
        logger.error(str(e).replace("\n","\t"))
        return render(request, Err.ERROR_PAGE)
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:45,代码来源:views.py

示例11: showContest

# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import getById [as 别名]
def showContest(request, cId):
    try:
        u = User.getSessionUser(request.session)
        if not u:
            raise Err(request, 'not login')
        
        c = Contest.getById(cId)
        cn = c.getContestNotice()
        try:
            c.canEnterContest(u)
        except:
            raise Err(request, 'no priv')

        c.course_class_name = unicode(c.course_class.getFullName())
        c.description = unicode(c.contest_description)
        c.title = unicode(c.contest_title)
        now = datetime.now()
        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
        if c.start_time+timedelta(minutes=c.length)<now:
            c.status = 'ended'
        elif c.start_time > now:
            c.status = 'scheduled'
        else:
            c.status = 'running'
        priv = Contest.hasPriv(c.course_class, u)

        problemList = c.getContestProblem()
        for cp, cp_res, cp_user_res in zip(problemList, getContestResult(c=c), getContestUserResult(c=c, u=u)):
            cp.index = cp.problem_index
            cp.title = unicode(cp.problem_title)
            cp.tlim = cp.problem.prob_time
            cp.mlim = cp.problem.prob_memory
            cp.ac = cp_res['ac_cnt']
            cp.sub = cp_res['sub_cnt']
            cp.ratio = cp_res['ac_ratio']
            cp.user_res = cp_user_res
        return render(request, 'newtpl/contest/showContest.html',
                {'contest': c, 'problem_list': problemList, 'contest_notice_list':cn,'ccid': c.course_class.id, 'tpl':{'has_priv': priv, 'nav_act':'contest',}})
    except Exception as e:
        return render(request, Err.ERROR_PAGE, {'errmsg': unicode(e), })
开发者ID:YLAsce,项目名称:oj,代码行数:44,代码来源:views.py

示例12: showContestProblemStatistics

# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import getById [as 别名]
def showContestProblemStatistics( request, p_index=None, cid=None):
    logger.info(str(request).replace("\n","\t"))
    """
    view used to show statistics of a problem in a contest
    """
    try:
        u = User.getSessionUser(request.session)
        if not u:
            raise Err( request, err='not login')

        cid = int(cid)
        c = Contest.getById(cid)

        p_index = p_index if p_index else ''

        try:
            contest_problem = ContestProblem.getBy( c, p_index)
        except:
            raise Err( request, err='no contestproblem', 
                    log_format=( '{0}'.format(p_index), ''), 
                    user_format=( u'{0}'.format( p_index), u'搞错了什么吧!'),
                    )

        if not contest_problem.contest.course_class.canBeManaged( u):
            raise Err( request, err = 'no priv')

        all_submissions = Submission.submissionList( cp=contest_problem )
        submissions = all_submissions.filter( status='Accepted').order_by('run_time')[:20]

        status_list = []
        for i in Const.STATUS_CN.iterkeys():
            status_list.append( { 'name': Const.STATUS_CN[i], 'number': all_submissions.filter( status=i).count()} )

        for sub_s in submissions:
            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/statistic/contest_problem.html', { 'submissions': submissions, 'contest_problem': contest_problem, 'status_list': status_list, 'tpl': { 'sp': True } })

    except Exception as e:
        logger.error(str(e).replace("\n","\t"))
        return render(request, Err.ERROR_PAGE, { 'errmsg': unicode(e) } )
开发者ID:vapour18,项目名称:oj,代码行数:44,代码来源:views.py

示例13: showBoardByDynamicScore

# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import getById [as 别名]
def showBoardByDynamicScore(request, cId):
    logger.info(str(request).replace("\n","\t"))
    try:
        u = User.getSessionUser(request.session)
        if not u:
            raise Err(request, 'not login')
        try:
            c = Contest.getById(cId)
        except:
            raise Err(request, 'no resource')

        try:
            c.canEnterContest(u)
        except:
            raise Err(request, 'no priv')

        return render(request,"newtpl/statistic/board_dynamic_score.html", {'contest': c, 'tpl': {'has_priv': Contest.hasPriv(c.course_class, u)}})
    except Exception as e:
        logger.error(str(e).replace("\n","\t"))
        return render(request, Err.ERROR_PAGE)
开发者ID:YLAsce,项目名称:oj,代码行数:22,代码来源:views.py

示例14: _showContest

# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import getById [as 别名]
def _showContest(request, cId):
    cId = int(cId)

    try:
        u = User.getSessionUser(request.session)
        if not u:
            raise Exception(u'请先登录')

        c = Contest.getById(cId)
        c.canEnterContest(u)
        #cc = c.course_class

        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

        cn = c.getContestNotice()

        if c.status != 'scheduled' or c.canUpdateContest(u):
            problemList = c.getContestProblem()
            for cp in problemList:
                cp.index = cp.problem_index
                cp.title = unicode(cp.problem_title)
                cp.tlim = cp.problem.prob_time
                cp.mlim = cp.problem.prob_memory

        return render(request, 'newtpl/contest/showContest.html',
                {'contest': c, 'problem_list': problemList, 'contest_notice_list': cn, 'ccid': c.course_class.id,
                    'tpl':{'has_priv': Contest.hasPriv(c.course_class, u),}})
    except Exception as e:
        return render(request, Const.ERROR_PAGE, {'errmsg':unicode(e),})
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:43,代码来源:views.py

示例15: addClarification

# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import getById [as 别名]
def addClarification(request, cid):
    logger.info(str(request).replace("\n","\t"))
    try:
        u = User.getSessionUser(request.session)
        if not u:
            raise Exception(Const.NOT_LOGGED_IN)
        c = Contest.getById(cid)
        if not c:
            raise Exception(Const.CONTEST_NOT_EXIST)

        has_priv = False
        try:
            c.canBeManaged(u)
            has_priv = True
        except:
            pass
        try:
            c.canEnterContest(u)
            has_priv = True
        except:
            pass
        if not has_priv:
            raise Exception('No Privilege!')
        
        if request.method != 'POST':
            return render(request, 'newtpl/contest/addClar.html', {'contest': c})

        form = ClarificationForm(request.POST)
        try:
            if form.is_valid():
                question = form.cleaned_data['question']
                Clarification.addClarification(question, u, c)
                return redirect('Contest:view_all_clars', cid)
            else:
                raise
        except:
            raise Exception('Invalid Question')
    except Exception as e:
        logger.error(unicode(e).replace('\n', '\t')) 
        return render(request, Err.ERROR_PAGE, {'errmsg': unicode(e)})    
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:42,代码来源:views.py


注:本文中的Contest.models.Contest.getById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。