From 48d48a0f3040115b75c9fc3d9f0126c7d25b2896 Mon Sep 17 00:00:00 2001 From: hohoTT <609029365@qq.com> Date: Sat, 22 Aug 2015 20:42:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=AF=94=E8=B5=9B?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contest/views.py | 12 +++-- .../oj/announcement/_announcement_panel.html | 12 +++++ template/oj/contest/contest_list.html | 51 +++++-------------- template/oj/problem/problem_list.html | 13 +---- utils/templatetags/contest.py | 29 +++++++++++ 5 files changed, 64 insertions(+), 53 deletions(-) create mode 100644 template/oj/announcement/_announcement_panel.html create mode 100644 utils/templatetags/contest.py diff --git a/contest/views.py b/contest/views.py index 0f0cf708..cabfff90 100644 --- a/contest/views.py +++ b/contest/views.py @@ -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}) diff --git a/template/oj/announcement/_announcement_panel.html b/template/oj/announcement/_announcement_panel.html new file mode 100644 index 00000000..f17a9ceb --- /dev/null +++ b/template/oj/announcement/_announcement_panel.html @@ -0,0 +1,12 @@ +
{{ forloop.counter }}. {{ item.title }}
+ {% endfor %} +| # | 比赛名称 | 开始时间 | -比赛模式 | 比赛类型 | 状态 | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {{ item.id }} | {{ item.title }} | {{ item.start_time }} | - {% ifequal item.mode 0 %} -acm模式 | - {% endifequal %} - {% ifequal item.mode 1 %} -AC数量模式 | - {% endifequal %} - {% ifequal item.mode 2 %} -AC总分排名模式 | - {% endifequal %} {% ifequal item.contest_type 0 %}小组赛 | @@ -54,27 +42,26 @@公开赛(密码保护) | {% endifequal %} - {% if now < item_start_time %} -比赛还未开始 | - {% elif item.start_time <= now and now <= item_end_time %} -比赛正在进行 | - {% else %} -比赛已结束 | - {% endif %} +{{ item|contest_status }} |