完善提交页面、提交列表和对应的后台逻辑

This commit is contained in:
virusdefender
2015-08-14 10:23:06 +08:00
parent 11a4c04443
commit 59ee24de45
16 changed files with 202 additions and 239 deletions

View File

@@ -13,12 +13,12 @@ from judger.result import result
from judger_controller.tasks import judge
from account.decorators import login_required
from problem.models import Problem
from utils.shortcuts import serializer_invalid_response, error_response, success_response
from utils.shortcuts import serializer_invalid_response, error_response, success_response, error_page
from .serializers import CreateSubmissionSerializer
def _create_mondodb_connection():
mongodb_setting = settings.DATABASES["mongodb"]
mongodb_setting = settings["mongodb_setting"]
connection = pymongo.MongoClient(host=mongodb_setting["HOST"], port=mongodb_setting["PORT"])
return connection["oj"]["oj_submission"]
@@ -66,13 +66,31 @@ class SubmissionnAPIView(APIView):
return error_response(u"提交不存在")
@login_required
def problem_my_submissions_list_page(request, problem_id):
collection = _create_mondodb_connection()
submissions = collection.find({"problem_id": int(problem_id), "user_id": request.user.id},
projection=["result", "accepted_answer_info", "create_time", "language"],
sort=[["create_time", -pymongo.ASCENDING]])
return render(request, "oj/problem/my_submissions_list.html", {"submissions": submissions})
try:
problem = Problem.objects.get(id=problem_id, visible=True)
except Problem.DoesNotExist:
return error_page(request, u"问题不存在")
return render(request, "oj/problem/my_submissions_list.html",
{"submissions": submissions, "problem": problem})
def my_submission(request, solution_id):
return render(request, "oj/problem/my_solution.html")
@login_required
def my_submission(request, submission_id):
collection = _create_mondodb_connection()
submission = collection.find_one({"user_id": request.user.id, "_id": ObjectId(submission_id)},
projection=["result", "accepted_answer_info", "create_time",
"language", "code", "problem_id", "info"])
if not submission:
return error_page(request, u"提交不存在")
try:
problem = Problem.objects.get(id=submission["problem_id"], visible=True)
except Problem.DoesNotExist:
return error_page(request, u"提交不存在")
return render(request, "oj/problem/my_submission.html", {"submission": submission, "problem": problem})