diff --git a/submission/views.py b/submission/views.py index 70ee700e..88c6d0dc 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 dd915a17..4f69d6fd 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 %}