diff --git a/submission/serializers.py b/submission/serializers.py index c64ada6c..e9f1052c 100644 --- a/submission/serializers.py +++ b/submission/serializers.py @@ -1,6 +1,8 @@ # coding=utf-8 from rest_framework import serializers +from account.models import User +from .models import Submission class CreateSubmissionSerializer(serializers.Serializer): @@ -8,3 +10,13 @@ class CreateSubmissionSerializer(serializers.Serializer): language = serializers.IntegerField() code = serializers.CharField(max_length=3000) + +class SubmissionSerializer(serializers.ModelSerializer): + user = serializers.SerializerMethodField("_get_submission_user") + + class Meta: + model = Submission + fields = ["id", "result", "create_time", "language", "user"] + + def _get_submission_user(self, obj): + return User.objects.get(id=obj.user_id).username \ No newline at end of file diff --git a/submission/views.py b/submission/views.py index 2ebc843e..10c77867 100644 --- a/submission/views.py +++ b/submission/views.py @@ -8,10 +8,11 @@ from rest_framework.views import APIView from judge.judger.result import result from judge.judger_controller.tasks import judge from account.decorators import login_required +from account.models import SUPER_ADMIN from problem.models import Problem -from utils.shortcuts import serializer_invalid_response, error_response, success_response, error_page +from utils.shortcuts import serializer_invalid_response, error_response, success_response, error_page, paginate from .models import Submission -from .serializers import CreateSubmissionSerializer +from .serializers import CreateSubmissionSerializer, SubmissionSerializer class SubmissionAPIView(APIView): @@ -70,12 +71,34 @@ def problem_my_submissions_list_page(request, problem_id): @login_required def my_submission(request, submission_id): try: - submission = Submission.objects.get(id=submission_id) + # 超级管理员可以查看所有的提交 + if request.user.admin_type != SUPER_ADMIN: + submission = Submission.objects.get(id=submission_id, user_id=request.user.id) + else: + submission = Submission.objects.get(id=submission_id) except Submission.DoesNotExist: return error_page(request, u"提交不存在") + try: problem = Problem.objects.get(id=submission.problem_id, visible=True) except Problem.DoesNotExist: return error_page(request, u"提交不存在") + if submission.info: + try: + info = json.loads(submission.info) + except Exception: + info = submission.info + else: + info = None return render(request, "oj/problem/my_submission.html", - {"submission": submission, "problem": problem}) \ No newline at end of file + {"submission": submission, "problem": problem, "info": info}) + + + +class SubmissionAdminAPIView(APIView): + def get(self, request): + problem_id = request.GET.get("problem_id", None) + if not problem_id: + return error_response(u"参数错误") + submissions = Submission.objects.filter(problem_id=problem_id).order_by("-create_time") + return paginate(request, submissions, SubmissionSerializer) \ No newline at end of file diff --git a/template/admin/group/group_detail.html b/template/admin/group/group_detail.html index 79cb1447..f99efad7 100644 --- a/template/admin/group/group_detail.html +++ b/template/admin/group/group_detail.html @@ -1,4 +1,10 @@
+

小组成员管理

diff --git a/template/admin/problem/edit_problem.html b/template/admin/problem/edit_problem.html index 0840d97c..f22eefa4 100644 --- a/template/admin/problem/edit_problem.html +++ b/template/admin/problem/edit_problem.html @@ -1,5 +1,11 @@
+
diff --git a/template/admin/problem/problem_list.html b/template/admin/problem/problem_list.html index c02e6683..01f86712 100644 --- a/template/admin/problem/problem_list.html +++ b/template/admin/problem/problem_list.html @@ -28,6 +28,7 @@
{{ el.total_accepted_number }}/{{ el.total_submit_number }} +
diff --git a/template/admin/problem/submission_list.html b/template/admin/problem/submission_list.html new file mode 100644 index 00000000..6d94dabd --- /dev/null +++ b/template/admin/problem/submission_list.html @@ -0,0 +1,28 @@ +
+

提交列表

+ + + + + + + + + + + + + + + + +
ID创建时间作者结果
{{ el.id }}{{ el.create_time|date("yyyy-MM-dd HH:mm:ss")}}{{ el.user }}{{ results[el.result] }} + 详情 +
+
+ 页数:{{ page }}/{{ totalPage }}   + + +
+
+ \ No newline at end of file diff --git a/template/oj/problem/my_submission.html b/template/oj/problem/my_submission.html index 524642f9..1aca690d 100644 --- a/template/oj/problem/my_submission.html +++ b/template/oj/problem/my_submission.html @@ -32,6 +32,17 @@

提交时间 : {{ submission.create_time }}

+ {% ifequal request.user.admin_type 2 %} +

本调试信息仅超级管理员可见

+ {% ifequal submission.result 7 %} +
System Error: {{ submission.info }}
+ {% else %} +
{{ info }}
+ {% endifequal %} + + {% endifequal %} + +