def showContest(request, cId): try: u = User.getSessionUser(request.session) if not u: raise Err(request, 'not login') c = Contest.getById(cId) 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' cn = c.getContestNotice() 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), })
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)
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)
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), })