From 5ac16a3c7f5dbad73e2851a0123be7c23a1f8f92 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Tue, 22 Sep 2015 14:28:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=98=BE=E7=A4=BA=E6=89=80?= =?UTF-8?q?=E6=9C=89=E6=8F=90=E4=BA=A4=E7=9A=84=E8=B0=83=E8=AF=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- submission/views.py | 30 ++++++++++++------- .../src/oj/problem/my_submissions_list.html | 5 +++- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/submission/views.py b/submission/views.py index 70ee700..88c6d0d 100644 --- a/submission/views.py +++ b/submission/views.py @@ -11,7 +11,7 @@ from rest_framework.views import APIView from judge.judger_controller.tasks import judge from judge.judger_controller.settings import redis_config from account.decorators import login_required -from account.models import SUPER_ADMIN +from account.models import SUPER_ADMIN, User from problem.models import Problem from contest.models import ContestProblem, Contest @@ -162,7 +162,11 @@ def my_submission_list_page(request, page=1): 我的所有提交的列表页 """ submissions = Submission.objects.filter(user_id=request.user.id, contest_id__isnull=True). \ - values("id", "problem_id", "result", "create_time", "accepted_answer_time", "language").order_by("-create_time") + values("id", "user_id", "problem_id", "result", "create_time", "accepted_answer_time", "language").order_by("-create_time") + + # 显示所有人的提交 这是管理员的调试功能 + show_all = request.GET.get("show_all", False) == "true" + language = request.GET.get("language", None) filter = None if language: @@ -173,14 +177,21 @@ def my_submission_list_page(request, page=1): submissions = submissions.filter(result=int(result)) filter = {"name": "result", "content": result} - # 为 submission 查询题目 因为提交页面经常会有重复的题目,缓存一下查询结果 - cache_result = {} + # 因为提交页面经常会有重复的题目和用户,缓存一下查询结果 + cache_result = {"problem": {}, "user": {}} for item in submissions: problem_id = item["problem_id"] - if problem_id not in cache_result: + if problem_id not in cache_result["problem"]: problem = Problem.objects.get(id=problem_id) - cache_result[problem_id] = problem.title - item["title"] = cache_result[problem_id] + cache_result["problem"][problem_id] = problem.title + item["title"] = cache_result["problem"][problem_id] + + if show_all: + user_id = item["user_id"] + if user_id not in cache_result["user"]: + user = User.objects.get(id=user_id) + cache_result["user"][user_id] = user + item["user"] = cache_result["user"][user_id] paginator = Paginator(submissions, 20) try: @@ -197,13 +208,10 @@ def my_submission_list_page(request, page=1): except Exception: pass - # 右侧的公告列表 - announcements = Announcement.objects.filter(is_global=True, visible=True).order_by("-create_time") - return render(request, "oj/submission/my_submissions_list.html", {"submissions": current_page, "page": int(page), "previous_page": previous_page, "next_page": next_page, "start_id": int(page) * 20 - 20, - "announcements": announcements, "filter": filter}) + "filter": filter, "show_all": show_all}) class SubmissionShareAPIView(APIView): diff --git a/template/src/oj/problem/my_submissions_list.html b/template/src/oj/problem/my_submissions_list.html index dd915a1..4f69d6f 100644 --- a/template/src/oj/problem/my_submissions_list.html +++ b/template/src/oj/problem/my_submissions_list.html @@ -27,7 +27,10 @@
{% for item in submissions %}