mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 08:23:20 +00:00
创建前台比赛列表
This commit is contained in:
parent
ea3e8841a9
commit
0bf84d1c40
@ -1,15 +1,18 @@
|
||||
# coding=utf-8
|
||||
import json
|
||||
import datetime
|
||||
from django.shortcuts import render
|
||||
from django.db import IntegrityError
|
||||
from django.utils import dateparse
|
||||
from django.db.models import Q
|
||||
from django.core.paginator import Paginator
|
||||
from rest_framework.views import APIView
|
||||
from utils.shortcuts import (serializer_invalid_response, error_response,
|
||||
success_response, paginate, rand_str, error_page)
|
||||
|
||||
from account.models import REGULAR_USER, ADMIN, SUPER_ADMIN
|
||||
from group.models import Group
|
||||
from announcement.models import Announcement
|
||||
|
||||
from .models import Contest, ContestProblem
|
||||
from .serializers import (CreateContestSerializer, ContestSerializer, EditContestSerializer,
|
||||
@ -17,7 +20,11 @@ from .serializers import (CreateContestSerializer, ContestSerializer, EditContes
|
||||
|
||||
|
||||
def contest_page(request, contest_id):
|
||||
pass
|
||||
try:
|
||||
contest = Contest.objects.get(id=contest_id, visible=True)
|
||||
except Contest.DoesNotExist:
|
||||
return error_page(request, u"比赛不存在")
|
||||
return render(request, "oj/contest/problems.html", {"contest": contest})
|
||||
|
||||
|
||||
class ContestAdminAPIView(APIView):
|
||||
@ -220,4 +227,42 @@ class ContestProblemAdminAPIView(APIView):
|
||||
contest_problem = contest_problem.filter(Q(title__contains=keyword) |
|
||||
Q(description__contains=keyword))
|
||||
|
||||
return paginate(request, contest_problem, ContestProblemSerializer)
|
||||
return paginate(request, contest_problem, ContestProblemSerializer)
|
||||
|
||||
|
||||
def contest_list_page(request, page=1):
|
||||
# 正常情况
|
||||
contests = Contest.objects.filter(visible=True)
|
||||
|
||||
# 搜索的情况
|
||||
keyword = request.GET.get("keyword", None)
|
||||
if keyword:
|
||||
contests = contests.filter(title__contains=keyword)
|
||||
|
||||
paginator = Paginator(contests, 20)
|
||||
try:
|
||||
current_page = paginator.page(int(page))
|
||||
except Exception:
|
||||
return error_page(request, u"不存在的页码")
|
||||
|
||||
previous_page = next_page = None
|
||||
|
||||
try:
|
||||
previous_page = current_page.previous_page_number()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
next_page = current_page.next_page_number()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 右侧的公告列表
|
||||
announcements = Announcement.objects.filter(is_global=True, visible=True).order_by("-create_time")
|
||||
# 系统当前时间
|
||||
now = datetime.datetime.now()
|
||||
return render(request, "oj/contest/contest_list.html",
|
||||
{"problems": current_page, "page": int(page),
|
||||
"previous_page": previous_page, "next_page": next_page,
|
||||
"keyword": keyword, "announcements": announcements,
|
||||
"now": now})
|
||||
|
@ -40,12 +40,15 @@ urlpatterns = [
|
||||
url(r'^api/admin/contest/$', ContestAdminAPIView.as_view(), name="contest_admin_api"),
|
||||
url(r'^api/admin/user/$', UserAdminAPIView.as_view(), name="user_admin_api"),
|
||||
url(r'^problem/(?P<problem_id>\d+)/$', "problem.views.problem_page", name="problem_page"),
|
||||
url(r'^contest/(?P<contest_id>\d+)/$', "contest.views.contest_page", name="contest_page"),
|
||||
url(r'^announcement/(?P<announcement_id>\d+)/$', "announcement.views.announcement_page",
|
||||
name="announcement_page"),
|
||||
url(r'^admin/contest/$', TemplateView.as_view(template_name="admin/contest/add_contest.html"),
|
||||
name="add_contest_page"),
|
||||
url(r'^problems/$', "problem.views.problem_list_page", name="problem_list_page"),
|
||||
url(r'^problems/(?P<page>\d+)/$', "problem.views.problem_list_page", name="problem_list_page"),
|
||||
url(r'^contests/$', "contest.views.contest_list_page", name="contest_list_page"),
|
||||
url(r'^contests/(?P<page>\d+)/$', "contest.views.contest_list_page", name="contest_list_page"),
|
||||
url(r'^admin/template/(?P<template_dir>\w+)/(?P<template_name>\w+).html$', AdminTemplateView.as_view(),
|
||||
name="admin_template"),
|
||||
url(r'^api/admin/group/$', GroupAdminAPIView.as_view(), name="group_admin_api"),
|
||||
|
106
template/oj/contest/contest_list.html
Normal file
106
template/oj/contest/contest_list.html
Normal file
@ -0,0 +1,106 @@
|
||||
{% extends "oj_base.html" %}
|
||||
{% block body %}
|
||||
{% load problem %}
|
||||
<div class="container main">
|
||||
<div class="row">
|
||||
<div class="col-lg-9">
|
||||
<div class="row">
|
||||
<div class="right">
|
||||
<form class="form-inline" method="get">
|
||||
<div class="form-group-sm">
|
||||
<input name="keyword" class="form-control" placeholder="请输入关键词">
|
||||
<input type="submit" value="搜索" class="btn btn-primary">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>#</th>
|
||||
<th>比赛名称</th>
|
||||
<th>开始时间</th>
|
||||
<th>比赛模式</th>
|
||||
<th>比赛类型</th>
|
||||
<th>状态</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for item in contests %}
|
||||
<tr>
|
||||
<th><span class="glyphicon glyphicon-ok ac-flag"></span></th>
|
||||
<th scope="row"><a href="/contest/{{ item.id }}/">{{ item.id }}</a></th>
|
||||
<td><a href="/contest/{{ item.id }}/">{{ item.title }}</a></td>
|
||||
<td>{{ item.start_time }}</td>
|
||||
{% ifequal item.mode 0 %}
|
||||
<td>acm模式</td>
|
||||
{% endifequal %}
|
||||
{% ifequal item.mode 1 %}
|
||||
<td>AC数量模式</td>
|
||||
{% endifequal %}
|
||||
{% ifequal item.mode 2 %}
|
||||
<td>AC总分排名模式</td>
|
||||
{% endifequal %}
|
||||
|
||||
{% ifequal item.contest_type 0 %}
|
||||
<td>小组赛</td>
|
||||
{% endifequal %}
|
||||
{% ifequal item.contest_type 1 %}
|
||||
<td>公开赛</td>
|
||||
{% endifequal %}
|
||||
{% ifequal item.contest_type 2 %}
|
||||
<td>公开赛(密码保护)</td>
|
||||
{% endifequal %}
|
||||
|
||||
{% if now < item_start_time %}
|
||||
<td>比赛还未开始</td>
|
||||
{% elif item.start_time <= now and now <= item_end_time %}
|
||||
<td>比赛正在进行</td>
|
||||
{% else %}
|
||||
<td>比赛已结束</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<nav>
|
||||
<ul class="pager">
|
||||
{% if previous_page %}
|
||||
<li class="previous"><a
|
||||
href="/problems/{{ previous_page }}/{% if keyword %}?keyword={{ keyword }}{% endif %}{% if tag %}?tag={{ tag }}{% endif %}">
|
||||
<span aria-hidden="true">←</span> 上一页</a></li>
|
||||
{% endif %}
|
||||
{% if next_page %}
|
||||
<li class="next"><a
|
||||
href="/problems/{{ next_page }}/{% if keyword %}?keyword={{ keyword }}{% endif %}{% if tag %}?tag={{ tag }}{% endif %}">下一页 <span
|
||||
aria-hidden="true">→</span></a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-3">
|
||||
<div class="panel panel-info">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">
|
||||
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
|
||||
公告
|
||||
</h3></div>
|
||||
<div class="panel-body">
|
||||
{% for item in announcements %}
|
||||
{{ forloop.counter }}. <a href="/announcement/{{ item.id }}/" target="_blank">{{ item.title }}</a>
|
||||
<br>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block js_block %}
|
||||
<script src="/static/js/app/oj/problem/problem_list.js"></script>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user