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
|
||||
import json
|
||||
import datetime
|
||||
from django.utils.timezone import localtime
|
||||
from django.shortcuts import render
|
||||
from django.db import IntegrityError
|
||||
from django.utils import dateparse
|
||||
@ -209,7 +210,7 @@ class ContestProblemAdminAPIView(APIView):
|
||||
"""
|
||||
比赛题目分页json api接口
|
||||
---
|
||||
response_serializer: ProblemSerializer
|
||||
response_serializer: ContestProblemSerializer
|
||||
"""
|
||||
contest_problem_id = request.GET.get("contest_problem_id", None)
|
||||
if contest_problem_id:
|
||||
@ -239,6 +240,11 @@ def contest_list_page(request, page=1):
|
||||
if 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)
|
||||
try:
|
||||
current_page = paginator.page(int(page))
|
||||
@ -262,7 +268,7 @@ def contest_list_page(request, page=1):
|
||||
# 系统当前时间
|
||||
now = datetime.datetime.now()
|
||||
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,
|
||||
"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" %}
|
||||
{% block body %}
|
||||
{% load problem %}
|
||||
{% load contest %}
|
||||
<div class="container main">
|
||||
<div class="row">
|
||||
<div class="col-lg-9">
|
||||
@ -18,11 +18,9 @@
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>#</th>
|
||||
<th>比赛名称</th>
|
||||
<th>开始时间</th>
|
||||
<th>比赛模式</th>
|
||||
<th>比赛类型</th>
|
||||
<th>状态</th>
|
||||
</tr>
|
||||
@ -30,19 +28,9 @@
|
||||
<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>
|
||||
@ -54,27 +42,26 @@
|
||||
<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 %}
|
||||
<td class="{{ item|contest_status_color }}">{{ item|contest_status }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</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>
|
||||
<ul class="pager">
|
||||
{% if previous_page %}
|
||||
<li class="previous"><a
|
||||
href="/problems/{{ previous_page }}/{% if keyword %}?keyword={{ keyword }}{% endif %}{% if tag %}?tag={{ tag }}{% endif %}">
|
||||
<li class="previous">
|
||||
<a href="/contests/{{ previous_page }}/{% if keyword %}?keyword={{ keyword }}{% endif %}{% if join %}?join={{ join }}{% 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
|
||||
<li class="next">
|
||||
<a href="/contests/{{ next_page }}/{% if keyword %}?keyword={{ keyword }}{% endif %}{% if join %}?join={{ join }}{% endif %}">下一页 <span
|
||||
aria-hidden="true">→</span></a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
@ -83,24 +70,12 @@
|
||||
</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>
|
||||
{% include "oj/announcement/_announcement_panel.html" %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block js_block %}
|
||||
<script src="/static/js/app/oj/problem/problem_list.js"></script>
|
||||
{% endblock %}
|
||||
@ -55,18 +55,7 @@
|
||||
</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>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% include "oj/announcement/_announcement_panel.html" %}
|
||||
<div class="panel panel-info">
|
||||
<div class="panel-heading">
|
||||
<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