def get_contestproblem(req):
    username, Flag = UserInit.init(req)
    if "contest_id" in req.GET:
        contest_id = req.GET["contest_id"]
    if "problem_id" in req.GET:
        problem_id = req.GET["problem_id"]
        tmp = contest_problem.objects.get(id=problem_id)
        problem = problemslist.objects.get(OJ=tmp.sojs, SID=tmp.pids)
        return render_to_response("contestproblem.html", {
            'username': username,
            'problem': problem,
            'Flag': Flag,
            'problem_id': problem_id,
            'contest_id': contest_id,
        },
                                  context_instance=RequestContext(req))
def get_contest_show(req):
    username, Flag = UserInit.init(req)
    if "id" in req.GET:
        contest_id = req.GET["id"]
        print contest_id
    ctest = contest.objects.get(id=contest_id)
    List = ContestTools.get_contest_problems_list(contest_id=contest_id)
    problem_id = List[0].id

    return render_to_response("contestshow.html", {
        'username': username,
        'MapList': List,
        'acontest': ctest,
        'Flag': Flag,
        'problem_id': problem_id
    },
                              context_instance=RequestContext(req))
def get_contest_rank(req):
    username, Flag = UserInit.init(req)
    if "contest_id" in req.GET:
        contest_id = req.GET["contest_id"]
        mycontest = contest.objects.get(id=contest_id)
        ProblemsList = ContestTools.get_contest_problems_list(
            contest_id=contest_id)
        problem_id = ProblemsList[0].id
        StatusList = user_status.objects.filter(
            contestID=contest_id).order_by('id')
        rank_list = ContestRank.GeneratorRank(ProblemsList, StatusList,
                                              mycontest.begintime,
                                              mycontest.endtime)
    return render_to_response("contestrank.html", {
        'username': username,
        'Flag': Flag,
        'contest_id': contest_id,
        'problem_id': problem_id,
        'rank_list': rank_list
    },
                              context_instance=RequestContext(req))
示例#4
0
def get_contest_list(req):
    username, Flag = UserInit.init(req)
    settershow = ""
    if req.method == 'POST':
        setter = req.POST['setter']
        settershow = setter
        print 'Find', settershow
    contest_list = contest.objects.filter(IsReady = True)
    if 'page' in req.GET:
        page = req.GET['page']
    else:
        page = 1
    title_show = ""
    setter_show = ""
    if req.method == 'POST':
        title_show = req.POST['title']
        setter_show = req.POST['setter']
    else:
        if 'title' in req.GET:
            title_show = req.GET['title']
        if 'setter' in req.GET:
            setter_show = req.GET['setter']
    if title_show != "":
        contest_list = contest_list.filter(title = title_show)
    if setter_show != "":
        contest_list = contest_list.filter(owner = setter)
    contest_list = contest_list.order_by('-begintime')
    paper = PagesManager(name = 'problem', now = int(page), data = contest_list, segment = 20)
    page = int(page)
    return render_to_response("contestlist.html", {'username' : username, 
                                                   'Flag' : Flag, 
                                                   'settershow' : settershow, 
                                                   'setter_show' : setter_show, 
                                                   'title_show' : title_show, 
                                                   'contest_list' : contest_list, 
                                                   'paper' : paper, }, 
                              context_instance = RequestContext(req))
示例#5
0
def editcontest(req):
    username, Flag = UserInit.init(req)
    if username ==  None or username =="":
        return HttpResponseRedirect('/login')
    #处理没有登录
    if 'id' in req.GET:
        contest_id = req.GET['id']
        Data, find = loadcontest(username, contest_id)
        if not find:
            return HttpResponseRedirect('/contestlist')
    else:
        return HttpResponseRedirect('/contestlist')
    #装载信息
    warning = ""
    show = False #提示信息
    OJList = DataManager.SuportOJList() #OJ列表
    
    start = Data.begintime.strftime('%Y-%m-%d %H:%M:%S %f') <= datetime.now().strftime('%Y-%m-%d %H:%M:%S %f')
    
    if not start:
        tmp = Editor.TimeSet(req, Data)
        beginTime = tmp['beginTime']
        hour = tmp['hour']
        minute = tmp['minute']
        if tmp['show']:
            show = True
            warning = tmp['warning']
        #需要选择是否能够修改开始 
    #开始时间设置

    tmp = Editor.LenSet(req, Data)
    d_day = tmp['d_day']
    d_hour = tmp['d_hour']
    d_minute = tmp['d_minute']
    if tmp['show']:
        show = True
        warning = tmp['warning']
    #比赛持续时间
    
    tmp = Editor.InfoSet(req, Data)
    if tmp['show']:
        show = True
        warning = tmp['warning']
    #信息维护
    
    if not start:
        tmp = Editor.ProblemsSet(req, Data)
        if tmp['show']:
            show = True
            warning = tmp['warning']
    #添加题目
    
    if req.method == 'POST':
        if 'submit' in req.POST and not show:
            if Data.title is None or Data.title == "":
                show = True
                warning = "Please input the contest' title !"
            elif (not start) and len(Data.list.all()) == 0:
                show = True
                warning = "Please add the problems !"
            elif (not start) and Data.begintime.strftime('%Y-%m-%d %H:%M:%S %f') < datetime.now().strftime('%Y-%m-%d %H:%M:%S %f'):
                #print 'Set', Data.begintime.strftime('%Y-%m-%d %H:%M:%S %f')
                #print 'Now', datetime.now().strftime('%Y-%m-%d %H:%M:%S %f')
                show = True
                warning = "The begin time must be later than now !"
            else:
                Data.save()
                TempStore.edit_contest(contest_id)
    start = not start
    print 'start =', start
    if start:
        return render_to_response('editcontest.html', 
                                  {'username' : username, 
                                   'Flag' : Flag, 
                                   'OJList' : OJList, 
                                   'warning' : warning, 
                                   'show' : show, 
                                   'problems_list' : Data.list.all(), 
                                   'data' : Data, 
                                   'beginTime' : beginTime, 
                                   'hour' : hour, 
                                   'minute' : minute, 
                                   'd_day' : d_day, 
                                   'd_hour' : d_hour, 
                                   'd_minute' : d_minute, 
                                   'start' : start, 
                                   'contestid' : contest_id, 
                                   }, 
                                  context_instance = RequestContext(req))
    print 'start =', start
    return render_to_response('editcontest.html', 
                              {'username' : username, 
                               'Flag' : Flag, 
                               'OJList' : OJList, 
                               'warning' : warning, 
                               'show' : show, 
                               'data' : Data, 
                               'd_day' : d_day, 
                               'd_hour' : d_hour, 
                               'd_minute' : d_minute, 
                               'start' : start, 
                               'contestid' : contest_id, 
                               }, 
                              context_instance = RequestContext(req))
示例#6
0
def addcontest(req):
    username, Flag = UserInit.init(req)
    if username ==  None or username =="":
        return HttpResponseRedirect('/login')
    #处理没有登录
    Data = loaddata(username)
    #装载信息
    warning = ""
    show = False #提示信息
    OJList = DataManager.SuportOJList() #OJ列表
    
    tmp = Editor.TimeSet(req, Data)
    beginTime = tmp['beginTime']
    hour = tmp['hour']
    minute = tmp['minute']
    if tmp['show']:
        show = True
        warning = tmp['warning']
    #开始时间设置

    tmp = Editor.LenSet(req, Data)
    d_day = tmp['d_day']
    d_hour = tmp['d_hour']
    d_minute = tmp['d_minute']
    if tmp['show']:
        show = True
        warning = tmp['warning']
    #比赛持续时间
    
    tmp = Editor.InfoSet(req, Data)
    if tmp['show']:
        show = True
        warning = tmp['warning']
    #信息维护
    
    tmp = Editor.ProblemsSet(req, Data)
    if tmp['show']:
        show = True
        warning = tmp['warning']
    #添加题目
    
    if req.method == 'POST':
        if 'submit' in req.POST and not show:
            if Data.title is None or Data.title == "":
                show = True
                warning = "Please input the contest' title !"
            elif len(Data.list.all()) == 0:
                show = True
                warning = "Please add the problems !"
            elif Data.begintime.strftime('%Y-%m-%d %H:%M:%S %f') < datetime.now().strftime('%Y-%m-%d %H:%M:%S %f'):
                #print 'Set', Data.begintime.strftime('%Y-%m-%d %H:%M:%S %f')
                #print 'Now', datetime.now().strftime('%Y-%m-%d %H:%M:%S %f')
                show = True
                warning = "The begin time must be later than now !"
            else:
                Data.save()
                TempStore.createcontest(username)
    return render_to_response('addcontest.html', 
                              {'username' : username, 
                               'Flag' : Flag, 
                               'OJList' : OJList, 
                               'warning' : warning, 
                               'show' : show, 
                               'problems_list' : Data.list.all(), 
                               'data' : Data, 
                               'beginTime' : beginTime, 
                               'hour' : hour, 
                               'minute' : minute, 
                               'd_day' : d_day, 
                               'd_hour' : d_hour, 
                               'd_minute' : d_minute, 
                               }, 
                              context_instance = RequestContext(req))
def get_contest_status(req):
    username, Flag = UserInit.init(req)
    if "contest_id" in req.GET:
        contest_id = req.GET["contest_id"]
        status_list = user_status.objects.filter(contestID=contest_id)
        List = ContestTools.get_contest_problems_list(contest_id=contest_id)
        problem_id = List[0].id
    oj_show = ['all']
    oj_show += DataManager.SuportOJList()
    result_show = DataManager.ResultList()
    language_show = ['all']
    language_show += DataManager.LanguageList()

    user_show = "",
    if req.POST:
        print 'POST'
        if cmp(req.POST["oj"], "all") != 0:
            status_list = status_list.filter(OJ=req.POST["oj"]).order_by('-id')
        find = oj_show.index(req.POST["oj"])
        first = oj_show[0]
        oj_show[0] = req.POST["oj"]
        oj_show[find] = first
        if cmp(req.POST["language"], "all") != 0:
            status_list = status_list.filter(
                language=req.POST["language"]).order_by('-id')
        find = language_show.index(req.POST["language"])
        first = language_show[0]
        language_show[0] = req.POST["language"]
        language_show[find] = first
        if cmp(req.POST["result"], "all") != 0:
            status_list = status_list.filter(
                result=req.POST["result"]).order_by('-id')
        find = result_show.index(req.POST["result"])
        first = result_show[0]
        result_show[0] = req.POST["result"]
        result_show[find] = first
        if cmp(req.POST["user"], "") != 0:
            status_list = status_list.filter(
                username=req.POST["user"]).order_by('-id')
        print 'Get =', req.POST['user']
        user_show = req.POST["user"]
    else:
        GET = req.GET
        if ('oj' not in GET) or cmp(GET["oj"], "all") == 0:
            status_list = status_list.order_by('-id')
            tmp = 'all'
        else:
            status_list = status_list.objects.filter(
                OJ=GET["oj"]).order_by('-id')
            tmp = GET['oj']
        find = oj_show.index(tmp)
        first = oj_show[0]
        oj_show[0] = tmp
        oj_show[find] = first
        tmp = 'all'
        if ('language' in GET) and cmp(GET["language"], "all") != 0:
            status_list = status_list.filter(
                language=GET["language"]).order_by('-id')
            tmp = GET["language"]
        find = language_show.index(tmp)
        first = language_show[0]
        language_show[0] = tmp
        language_show[find] = first
        tmp = 'all'
        if ('result' in GET) and cmp(GET["result"], "all") != 0:
            status_list = status_list.filter(
                result=GET["result"]).order_by('-id')
            tmp = GET['result']
        find = result_show.index(tmp)
        first = result_show[0]
        result_show[0] = tmp
        result_show[find] = first
        if ('user' in GET) and cmp(GET["user"], "") != 0:
            status_list = status_list.filter(
                username=GET["user"]).order_by('-id')
            user_show = GET["user"]
    if req.POST:
        if cmp(req.POST["ProID"], "") != 0:
            ProID_show = req.POST["ProID"]
            status_list = status_list.filter(problemID=ProID_show)
    else:
        if ('ProID' in req.GET):
            ProID_show = req.GET["ProID"]
            status_list = status_list.filter(problemID=ProID_show)

    return render_to_response("conteststatus.html", {
        'username': username,
        'Flag': Flag,
        'contest_id': contest_id,
        'status_list': status_list,
        'problem_id': problem_id,
        'oj_show': oj_show,
        'result_show': result_show,
        'language_show': language_show,
        'user_show': user_show,
    },
                              context_instance=RequestContext(req))