山东大学-VirtualJudge-总结5

2017-05-25  本文已影响0人  LJCgeorge

最近这几天,在学习了OJcontest 的基础上,实现了VJ自己的contest 的基本界面

Contest后台代码####

def contest(req):
    search = req.GET.get('search')
    if search:
        query = Contest.objects.filter(Q(name__icontains=search) | Q(uid__username__icontains=search))
    else:
        query = Contest.objects.all()
    pg = req.GET.get('pg')
    if not pg:
        pg = 1
    pg = int(pg)

    max_cnt = query.count()
    start = max(pg - PAGE_NUMBER_EVERY_PAGE, 1)
    end = min(pg + PAGE_NUMBER_EVERY_PAGE, max_cnt)

    lst = query[(pg - 1) * LIST_NUMBER_EVERY_PAGE:pg * LIST_NUMBER_EVERY_PAGE]

    return ren2res('contest.html', req, {'page': range(start, end + 1), 'list': lst})


@login_required
def contest_detail(req, cid):
    contest = Contest.objects.get(id=cid)
    # time = datetime.datetime.now(pytz.timezone(pytz.country_timezones('cn')[0]))
    # time = datetime.datetime.now()
    time = timezone.now()
    if time > contest.start_time:
        start = True
    else:
        start = False
    if contest.private:
        #print(problems)
        # print('contest.accounts')
        # print(contest.accounts.all())
        if req.user.is_superuser==False and req.user.info not in contest.accounts.all() :
            return ren2res("contest/contest.html", req, {'contest': contest, 'err': "You do not have access to this contest."})
    if start:
        problems = contest.get_problem_list()
        length = len(problems)
        problems_status = [0 for i in range(length)]

        for i in range(length):
            problems[i].append(len(Status.objects.filter(user = req.user).filter(pro = problems[i][2]).filter(result = 'Accepted')))#changes
        return ren2res("contest/contest.html", req, {'contest': contest, 'problems': problems, 'problem': problems[0][2]})
    else:
        return ren2res("contest/contest.html", req, {'contest': contest, 'err': "Just wait."})

def page_not_found(req):
    return ren2res("404.html", req, {})

效果截图####

contest-select contest-inside

但是submitrank等基本功能还有待进一步的实现。

上一篇下一篇

猜你喜欢

热点阅读