mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-11-04 14:49:58 +08:00
增加了比赛列表页
This commit is contained in:
parent
0bf84d1c40
commit
48d48a0f30
@ -1,6 +1,7 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
import json
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
|
from django.utils.timezone import localtime
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.utils import dateparse
|
from django.utils import dateparse
|
||||||
@ -209,7 +210,7 @@ class ContestProblemAdminAPIView(APIView):
|
|||||||
"""
|
"""
|
||||||
比赛题目分页json api接口
|
比赛题目分页json api接口
|
||||||
---
|
---
|
||||||
response_serializer: ProblemSerializer
|
response_serializer: ContestProblemSerializer
|
||||||
"""
|
"""
|
||||||
contest_problem_id = request.GET.get("contest_problem_id", None)
|
contest_problem_id = request.GET.get("contest_problem_id", None)
|
||||||
if contest_problem_id:
|
if contest_problem_id:
|
||||||
@ -239,6 +240,11 @@ def contest_list_page(request, page=1):
|
|||||||
if keyword:
|
if keyword:
|
||||||
contests = contests.filter(title__contains=keyword)
|
contests = contests.filter(title__contains=keyword)
|
||||||
|
|
||||||
|
# 筛选我能参加的比赛
|
||||||
|
join = request.GET.get("join", None)
|
||||||
|
if join:
|
||||||
|
contests = Contest.objects.filter(Q(contest_type__in=[1, 2]) | Q(groups__in=request.user.group_set.all()))
|
||||||
|
|
||||||
paginator = Paginator(contests, 20)
|
paginator = Paginator(contests, 20)
|
||||||
try:
|
try:
|
||||||
current_page = paginator.page(int(page))
|
current_page = paginator.page(int(page))
|
||||||
@ -262,7 +268,7 @@ def contest_list_page(request, page=1):
|
|||||||
# 系统当前时间
|
# 系统当前时间
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
return render(request, "oj/contest/contest_list.html",
|
return render(request, "oj/contest/contest_list.html",
|
||||||
{"problems": current_page, "page": int(page),
|
{"contests": current_page, "page": int(page),
|
||||||
"previous_page": previous_page, "next_page": next_page,
|
"previous_page": previous_page, "next_page": next_page,
|
||||||
"keyword": keyword, "announcements": announcements,
|
"keyword": keyword, "announcements": announcements,
|
||||||
"now": now})
|
"join": join, "now": now})
|
||||||
|
|||||||
12
template/oj/announcement/_announcement_panel.html
Normal file
12
template/oj/announcement/_announcement_panel.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<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 %}
|
||||||
|
<p>{{ forloop.counter }}. <a href="/announcement/{{ item.id }}/" target="_blank">{{ item.title }}</a></p>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{% extends "oj_base.html" %}
|
{% extends "oj_base.html" %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{% load problem %}
|
{% load contest %}
|
||||||
<div class="container main">
|
<div class="container main">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-9">
|
<div class="col-lg-9">
|
||||||
@ -18,11 +18,9 @@
|
|||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>比赛名称</th>
|
<th>比赛名称</th>
|
||||||
<th>开始时间</th>
|
<th>开始时间</th>
|
||||||
<th>比赛模式</th>
|
|
||||||
<th>比赛类型</th>
|
<th>比赛类型</th>
|
||||||
<th>状态</th>
|
<th>状态</th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -30,19 +28,9 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for item in contests %}
|
{% for item in contests %}
|
||||||
<tr>
|
<tr>
|
||||||
<th><span class="glyphicon glyphicon-ok ac-flag"></span></th>
|
|
||||||
<th scope="row"><a href="/contest/{{ item.id }}/">{{ item.id }}</a></th>
|
<th scope="row"><a href="/contest/{{ item.id }}/">{{ item.id }}</a></th>
|
||||||
<td><a href="/contest/{{ item.id }}/">{{ item.title }}</a></td>
|
<td><a href="/contest/{{ item.id }}/">{{ item.title }}</a></td>
|
||||||
<td>{{ item.start_time }}</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 %}
|
{% ifequal item.contest_type 0 %}
|
||||||
<td>小组赛</td>
|
<td>小组赛</td>
|
||||||
@ -54,27 +42,26 @@
|
|||||||
<td>公开赛(密码保护)</td>
|
<td>公开赛(密码保护)</td>
|
||||||
{% endifequal %}
|
{% endifequal %}
|
||||||
|
|
||||||
{% if now < item_start_time %}
|
<td class="{{ item|contest_status_color }}">{{ item|contest_status }}</td>
|
||||||
<td>比赛还未开始</td>
|
|
||||||
{% elif item.start_time <= now and now <= item_end_time %}
|
|
||||||
<td>比赛正在进行</td>
|
|
||||||
{% else %}
|
|
||||||
<td>比赛已结束</td>
|
|
||||||
{% endif %}
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>仅显示当前可参加的比赛
|
||||||
|
<input id="join" type="checkbox" {% if join %}checked{% endif %} onchange="if(this.checked){location.href='/contests/?join=True'}else{location.href='/contests/'}">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
<nav>
|
<nav>
|
||||||
<ul class="pager">
|
<ul class="pager">
|
||||||
{% if previous_page %}
|
{% if previous_page %}
|
||||||
<li class="previous"><a
|
<li class="previous">
|
||||||
href="/problems/{{ previous_page }}/{% if keyword %}?keyword={{ keyword }}{% endif %}{% if tag %}?tag={{ tag }}{% endif %}">
|
<a href="/contests/{{ previous_page }}/{% if keyword %}?keyword={{ keyword }}{% endif %}{% if join %}?join={{ join }}{% endif %}">
|
||||||
<span aria-hidden="true">←</span> 上一页</a></li>
|
<span aria-hidden="true">←</span> 上一页</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if next_page %}
|
{% if next_page %}
|
||||||
<li class="next"><a
|
<li class="next">
|
||||||
href="/problems/{{ next_page }}/{% if keyword %}?keyword={{ keyword }}{% endif %}{% if tag %}?tag={{ tag }}{% endif %}">下一页 <span
|
<a href="/contests/{{ next_page }}/{% if keyword %}?keyword={{ keyword }}{% endif %}{% if join %}?join={{ join }}{% endif %}">下一页 <span
|
||||||
aria-hidden="true">→</span></a></li>
|
aria-hidden="true">→</span></a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
@ -83,24 +70,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-lg-3">
|
<div class="col-lg-3">
|
||||||
<div class="panel panel-info">
|
{% include "oj/announcement/_announcement_panel.html" %}
|
||||||
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
{% block js_block %}
|
{% block js_block %}
|
||||||
<script src="/static/js/app/oj/problem/problem_list.js"></script>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@ -55,18 +55,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-lg-3">
|
<div class="col-lg-3">
|
||||||
<div class="panel panel-info">
|
{% include "oj/announcement/_announcement_panel.html" %}
|
||||||
<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>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="panel panel-info">
|
<div class="panel panel-info">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h3 class="panel-title">
|
<h3 class="panel-title">
|
||||||
|
|||||||
29
utils/templatetags/contest.py
Normal file
29
utils/templatetags/contest.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
import datetime
|
||||||
|
from django.utils.timezone import localtime
|
||||||
|
|
||||||
|
|
||||||
|
def get_contest_status(contest):
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
if localtime(contest.start_time).replace(tzinfo=None) > now:
|
||||||
|
return "没有开始"
|
||||||
|
if localtime(contest.end_time).replace(tzinfo=None) < now:
|
||||||
|
return "已经结束"
|
||||||
|
return "正在进行"
|
||||||
|
|
||||||
|
|
||||||
|
def get_contest_status_color(contest):
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
if localtime(contest.start_time).replace(tzinfo=None) > now:
|
||||||
|
return "info"
|
||||||
|
if localtime(contest.end_time).replace(tzinfo=None) < now:
|
||||||
|
return "warning"
|
||||||
|
return "success"
|
||||||
|
|
||||||
|
|
||||||
|
from django import template
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
register.filter("contest_status", get_contest_status)
|
||||||
|
register.filter("contest_status_color", get_contest_status_color)
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user