From 4e6465ff26791c28968301f52da566a2dcc39e89 Mon Sep 17 00:00:00 2001 From: virusdefender Date: Sat, 23 Apr 2016 23:04:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=98=AF=E5=90=A6=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=85=A8=E9=83=A8=E7=9A=84=E6=8F=90=E4=BA=A4=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oj/settings.py | 3 +++ submission/views.py | 26 ++++++++++++------- .../oj/submission/my_submissions_list.html | 9 +++++-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/oj/settings.py b/oj/settings.py index 9463718b..40f4feb2 100644 --- a/oj/settings.py +++ b/oj/settings.py @@ -184,3 +184,6 @@ TOKEN_BUCKET_DEFAULT_CAPACITY = 50 # 单位:每分钟 TOKEN_BUCKET_FILL_RATE = 2 + +# 是否显示所有人的提交, False就只显示自己的 +SHOW_ALL_SUBMISSIONS_LIST = False diff --git a/submission/views.py b/submission/views.py index b482326a..2bdd432a 100644 --- a/submission/views.py +++ b/submission/views.py @@ -242,8 +242,8 @@ def my_submission_list_page(request, page=1): """ 我的所有提交的列表页 """ - # 显示所有人的提交 这是管理员的调试功能 - show_all = request.GET.get("show_all", False) == "true" and request.user.admin_type == SUPER_ADMIN + # 是否显示所有人的提交 + show_all = settings.SHOW_ALL_SUBMISSIONS_LIST or request.GET.get("show_all", False) == "true" if show_all: submissions = Submission.objects.filter(contest_id__isnull=True) else: @@ -261,6 +261,12 @@ def my_submission_list_page(request, page=1): submissions = submissions.filter(result=int(result)) filter = {"name": "result", "content": result} + paginator = Paginator(submissions, 20) + try: + submissions = paginator.page(int(page)) + except Exception: + return error_page(request, u"不存在的页码") + # 因为提交页面经常会有重复的题目和用户,缓存一下查询结果 cache_result = {"problem": {}, "user": {}} for item in submissions: @@ -277,23 +283,23 @@ def my_submission_list_page(request, page=1): cache_result["user"][user_id] = user item["user"] = cache_result["user"][user_id] - paginator = Paginator(submissions, 20) - try: - current_page = paginator.page(int(page)) - except Exception: - return error_page(request, u"不存在的页码") + if item["user"].id == request.user.id or request.user.admin_type == SUPER_ADMIN: + item["show_link"] = True + else: + item["show_link"] = False + previous_page = next_page = None try: - previous_page = current_page.previous_page_number() + previous_page = submissions.previous_page_number() except Exception: pass try: - next_page = current_page.next_page_number() + next_page = submissions.next_page_number() except Exception: pass return render(request, "oj/submission/my_submissions_list.html", - {"submissions": current_page, "page": int(page), + {"submissions": submissions, "page": int(page), "previous_page": previous_page, "next_page": next_page, "start_id": int(page) * 20 - 20, "filter": filter, "show_all": show_all}) diff --git a/template/src/oj/submission/my_submissions_list.html b/template/src/oj/submission/my_submissions_list.html index e298afb7..2bce9726 100644 --- a/template/src/oj/submission/my_submissions_list.html +++ b/template/src/oj/submission/my_submissions_list.html @@ -10,6 +10,7 @@ # + {% if show_all %}用户{% endif %} 题目名称 提交时间 @@ -51,9 +52,13 @@ {% for item in submissions %} - {{ forloop.counter |add:start_id }} - {% if show_all %}({{ item.user.username }}){% endif %} + {% if item.show_link %} + {{ forloop.counter |add:start_id }} + {% else %} + {{ forloop.counter |add:start_id }} + {% endif %} + {% if show_all %}{{ item.user.username }}{% endif %} {{ item.title }}