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


Python models.Contest类代码示例

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


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

示例1: holdContest

def holdContest(request):
	
	f=HoldContestForm()
	dc = {'form':f}
	context = RequestContext(request, dc)
	if request.method == "POST":
		f=HoldContestForm(request.POST)
		if not f.is_valid():
			dc = {'form':f}
			context = RequestContext(request, dc)
			#raise Http404
			return render_to_response('holdContest.html',context)
		else:
			contest=Contest()
			context = RequestContext(request,dc)
		#	contest.adminID = User.objects.filter(User.username="sen3")[0]
			contest.contestName_f = f.cleaned_data['contestName']
			contest.contestpwd_f = f.cleaned_data['contestpwd']
			contest.termsCond = f.cleaned_data['termsCond']
			contest.contestFromDate = f.cleaned_data['contestFromDate']
			contest.contestToDate = f.cleaned_data['contestToDate']
			contest.contestFromTime = f.cleaned_data['contestFromTime']
			contest.contestToTime = f.cleaned_data['contestToTime']
			#contest.isApproved = False
			contest.save()
			f=HoldContestForm()
			#contestID = contest.contestID
			
			return HttpResponse("Your contest is send to admin for approval%s"%request.path)
	else:
		return render_to_response('holdContest.html',context)
开发者ID:pankajb64,项目名称:ecodena,代码行数:31,代码来源:views.py

示例2: listContestByPriv

def listContestByPriv(request, ccId, pageId='1'):
    """
    view used to list all contest a user can manage, course_class restricted
    """
    try:
        u = User.getSessionUser(request.session)
        if not u:
            messages.info(request, u'请先登录')
            return render(request, 'newtpl/contest/contestListByPriv.html')
        
        cc = CourseClass.getById(ccId)
        if not Contest.hasPriv(cc, u):
            raise Exception(Const.NOT_PVLG)
            
        contestList = Contest.getByCourseClass(cc)
        now = datetime.now()
        
        for c in contestList:
            c.course_class_name = unicode(c.course_class.getFullName())
            c.title = unicode(c.contest_title)
            if c.start_time+timedelta(minutes=c.length)<now:
                c.status = 'ended'
            elif c.start_time > now:
                c.status = 'scheduled'
            else:
                c.status = 'running'

        paginator = Paginator(contestList, Const.CONTEST_PER_PAGE)
        pageId = min(max(int(pageId), 1), paginator.num_pages)
        return render(request, 'newtpl/contest/contestListByPriv.html',
                      {'contest_list': paginator.page(pageId),  'course_class': cc,
                       'tpl':{'has_priv': True, 'nav_act':'contest',}})
    except Exception as e:
        return render(request, Const.ERROR_PAGE, {'errmsg': unicode(e), })
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:34,代码来源:views.py

示例3: addContest

def addContest(request, ccId):
    try:
        u = User.getSessionUser(request.session)
        if not u:
            raise Err(request, 'not login')
        
        try:
            cc = CourseClass.getById(ccId)
        except:
            raise Err(request, 'no resource')

        try:
            Contest.canAddContest(cc, u)
        except:
            raise Err(request, 'no priv')

        recentProblem = Problem.problemListByAuthor(u)

        if request.method == 'POST':
            form = contestForm(request.POST)
            pIdList = request.POST.getlist('problem_id')
            #pIdList =  Problem.problemList(u)

            pTitleList = request.POST.getlist('problem_title_custom')
            pCnt = len(pIdList)
            if form.is_valid():
                for i in xrange(pCnt):
                    p = Problem.getById(pIdList[i])
                    if not p.canViewProblem(u):
                        raise Err(request, 'no problem priv')

                pInfos = [(pIdList[i], pTitleList[i], chr(65+i)) for i in xrange(pCnt)]
                cTitle = form.cleaned_data['title']
                cDesc = form.cleaned_data['desc']
                cStartDate = form.cleaned_data['start_date']
                cStartTime = form.cleaned_data['start_time']
                cLength = form.cleaned_data['length']
                cBoardStop = form.cleaned_data['board_stop']
                cType = form.cleaned_data['contest_type']
                cBoardType = form.cleaned_data['board_type']
                permitLang = reduce(add, [Const.LANG_MASK[lang] for lang in form.cleaned_data['lang_limit']])
                c = Contest.addContest(u, cc, cTitle, pInfos, datetime.combine(cStartDate, cStartTime),
                                       cDesc, cLength, cBoardStop, cType, cBoardType, permitLang)
                return redirect('Contest:show_contest', c.cid)
            else:
                problemList = [{'pid': pIdList[x], 'title': pTitleList[x], 'origTitle':Problem.getById(pIdList[x]).prob_title} for x in xrange(pCnt)]
                return render(request, 'newtpl/contest/addContest.html', {'cc':cc,
                    'form': form, 'recent_problem': recentProblem,
                               'problem_list': problemList, 'tpl':{'has_priv': True, 'sp': True, }})
        else:
            form = contestForm()
            return render(request, 'newtpl/contest/addContest.html', {'cc':cc,
                'form': form, 'recent_problem': recentProblem, 
                'tpl':{'has_priv': True, 'sp': True, }})
    except Exception as e:
        messages.info(request, unicode(e))
        return render(request, Err.ERROR_PAGE)
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:57,代码来源:views.py

示例4: showContestNotice

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,代码行数:14,代码来源:views.py

示例5: updateContestNotice

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,代码行数:33,代码来源:views.py

示例6: viewAllClarifications

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,代码行数:27,代码来源:views.py

示例7: listContestByAuthor

def listContestByAuthor(request, pageId='1'):
    """
    view used to list all contest created by the specific user
    """
    try:
        u = User.getSessionUser(request.session)
        if not u:
            messages.info(request, u'请先登录')
            return render(request, 'newtpl/contest/contestListByAuthor.html')
            
        contestList = Contest.getByAuthor(u)
        now = datetime.now()
        for c in contestList:
            c.course_class_name = unicode(c.course_class.getFullName())
            c.title = unicode(c.contest_title)
            if c.start_time+timedelta(minutes=c.length)<now:
                c.status = 'ended'
            elif c.start_time > now:
                c.status = 'scheduled'
            else:
                c.status = 'running'

        paginator = Paginator(contestList, Const.CONTEST_PER_PAGE)
        pageId = min(max(int(pageId), 1), paginator.num_pages)
        return render(request, 'newtpl/contest/contestListByAuthor.html', {
            'contest_list': paginator.page(pageId), 'tpl':{'has_priv': True, 'nav_act':'contest',}})
    except Exception as e:
        return render(request, Const.ERROR_PAGE, {'errmsg': unicode(e), })
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:28,代码来源:views.py

示例8: addRecord

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,代码行数:27,代码来源:views.py

示例9: board

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,代码行数:59,代码来源:views.py

示例10: listContestByUser

def listContestByUser(request, pageId='1'):
    """
    view used to list all contest a user can participate
    """

    logger.info(str(request).replace("\n","\t"))
    tpl = {'nav_act':'contest'}

    try:
        u = User.getSessionUser(request.session)
        if not u:
            messages.info(request, u'请先登录')
            contestList = None
        else:
            now = datetime.now()
            if u.priv == 'student':
                contestList = Contest.getByStudent(u)
            else:
                contestList = Contest.getByAdmin(u)
                
            for c in contestList:
                c.course_class_name = unicode(c.course_class.getFullName())
                c.title = unicode(c.contest_title)
                if c.start_time+timedelta(minutes=c.length)<now:
                    c.status = 'ended'
                elif c.start_time > now:
                    c.status = 'scheduled'
                else:
                    c.status = 'running'

            paginator = Paginator(contestList, Const.CONTEST_PER_PAGE)
            pageId = min(max(int(pageId), 1), paginator.num_pages)

        if contestList and contestList.count>0:
            return render(request, 'newtpl/contest/contestListByUser.html', {
                'contest_list': paginator.page(pageId), 'tpl':tpl})
        else:
            return render(request, 'newtpl/contest/contestListByUser.html', {
                'tpl':tpl, 'err_msg_list': [
                    u'您暂时没有可以参加的测验。',
                    u'不如走出教室,呼吸一下新鲜空气,给家人打个电话,陪陪妹子?'
                    ]})

    except Exception as e:
        return render(request, Const.ERROR_PAGE, {'errmsg': unicode(e), })
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:45,代码来源:views.py

示例11: showContest

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,代码行数:42,代码来源:views.py

示例12: releaseBoardTime

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,代码行数:20,代码来源:views.py

示例13: _showContest

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,代码行数:41,代码来源:views.py

示例14: showResult

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,代码行数:53,代码来源:views.py

示例15: boardDetail

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,代码行数:15,代码来源:views.py


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