diff --git a/oj/urls.py b/oj/urls.py index 3165c1a0..67755dfd 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -50,9 +50,9 @@ urlpatterns = [ url(r'^api/admin/problem/$', ProblemAdminAPIView.as_view(), name="problem_admin_api"), url(r'^api/admin/test_case_upload/$', TestCaseUploadAPIView.as_view(), name="test_case_upload_api"), url(r'^api/admin/tag/$', ProblemTagAdminAPIView.as_view(), name="problem_tag_admin_api"), - url(r'^problem/(?P\d+)/my_solutions/', "problem.views.problem_my_solutions_list_page", - name="problem_my_solutions_page"), - url(r'^my_solution/(?P\d+)/$', "problem.views.my_solution", name="my_solution_page"), + url(r'^problem/(?P\d+)/my_solutions/', "submission.views.problem_my_submissions_list_page", + name="problem_my_submissions_page"), + url(r'^my_solution/(?P\d+)/$', "submission.views.my_submission", name="my_submission_page"), url(r'^api/admin/join_group_request/$', JoinGroupRequestAdminAPIView.as_view(), name="join_group_request_admin_api"), diff --git a/problem/migrations/0006_merge.py b/problem/migrations/0006_merge.py new file mode 100644 index 00000000..f24e12dd --- /dev/null +++ b/problem/migrations/0006_merge.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('problem', '0005_auto_20150813_1807'), + ('problem', '0004_auto_20150812_2254'), + ] + + operations = [ + ] diff --git a/problem/views.py b/problem/views.py index fe201274..a65aa4c3 100644 --- a/problem/views.py +++ b/problem/views.py @@ -47,15 +47,6 @@ def problem_page(request, problem_id): return render(request, "oj/problem/problem.html", {"problem": problem, "samples": json.loads(problem.samples)}) -def problem_my_solutions_list_page(request, problem_id): - return render(request, "oj/problem/my_solutions_list.html") - - -def my_solution(request, solution_id): - return render(request, "oj/problem/my_solution.html") - - - class ProblemAdminAPIView(APIView): def post(self, request): """ @@ -197,7 +188,7 @@ class TestCaseUploadAPIView(APIView): os.mkdir(test_case_dir) for name in l: f = open(test_case_dir + name, "wb") - f.write(test_case_file.read(name)) + f.write(test_case_file.read(name).replace("\r\n", "\n")) f.close() l.sort() diff --git a/static/src/js/app/oj/problem/problem.js b/static/src/js/app/oj/problem/problem.js index 6826e7b2..141405a1 100644 --- a/static/src/js/app/oj/problem/problem.js +++ b/static/src/js/app/oj/problem/problem.js @@ -25,8 +25,7 @@ require(["jquery", "code_mirror", "csrf", "bs_alert"], function ($, code_mirror, } - function get_result_html(result) { - console.log(result); + function get_result_html(data) { // 0 结果正确 1 运行错误 2 超时 3 超内存 4 编译错误 // 5 格式错误 6 结果错误 7 系统错误 8 等待判题 var results = { @@ -42,14 +41,16 @@ require(["jquery", "code_mirror", "csrf", "bs_alert"], function ($, code_mirror, }; var html = ''; - console.log(html); + results[data.result].message + + '!   '; + if (!data.result) { + html += "CPU time: " + data.accepted_answer_info.time + "ms   "; + } + html += ('查看详情 '); + return html; } @@ -67,7 +68,7 @@ require(["jquery", "code_mirror", "csrf", "bs_alert"], function ($, code_mirror, } else { hide_loading(); - $("#result").html(get_result_html(data.data.result)); + $("#result").html(get_result_html(data.data)); } } else { @@ -84,7 +85,7 @@ require(["jquery", "code_mirror", "csrf", "bs_alert"], function ($, code_mirror, show_loading(); - if(!code){ + if(!code.trim()){ bs_alert("请填写代码!"); hide_loading(); return false; diff --git a/submission/views.py b/submission/views.py index 83cfb886..3d115a01 100644 --- a/submission/views.py +++ b/submission/views.py @@ -1,4 +1,5 @@ # coding=utf-8 +import datetime import pymongo from bson.objectid import ObjectId @@ -16,12 +17,13 @@ from utils.shortcuts import serializer_invalid_response, error_response, success from .serializers import CreateSubmissionSerializer -class SubmissionnAPIView(APIView): - def _create_mondodb_connection(self): +def _create_mondodb_connection(): mongodb_setting = settings.DATABASES["mongodb"] connection = pymongo.MongoClient(host=mongodb_setting["HOST"], port=mongodb_setting["PORT"]) return connection["oj"]["oj_submission"] + +class SubmissionnAPIView(APIView): @login_required def post(self, request): """ @@ -35,6 +37,7 @@ class SubmissionnAPIView(APIView): # data["language"] = int(data["language"]) data["user_id"] = request.user.id data["result"] = result["waiting"] + data["create_time"] = datetime.datetime.now() try: problem = Problem.objects.get(id=data["problem_id"]) except Problem.DoesNotExist: @@ -53,8 +56,23 @@ class SubmissionnAPIView(APIView): submission_id = request.GET.get("submission_id", None) if not submission_id: return error_response(u"参数错误") - submission = self._create_mondodb_connection().find_one({"_id": ObjectId(submission_id), "user_id": request.user.id}) + submission = _create_mondodb_connection().find_one({"_id": ObjectId(submission_id), "user_id": request.user.id}) if submission: - return success_response({"result": submission["result"]}) + response_data = {"result": submission["result"]} + if submission["result"] == 0: + response_data["accepted_answer_info"] = submission["accepted_answer_info"] + return success_response(response_data) else: return error_response(u"提交不存在") + + +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"], + sort=[["create_time", -pymongo.ASCENDING]]) + return render(request, "oj/problem/my_solutions_list.html", {"submissions": submissions}) + + +def my_submission(request, solution_id): + return render(request, "oj/problem/my_solution.html") \ No newline at end of file diff --git a/template/oj/problem/problem.html b/template/oj/problem/problem.html index f3a30211..bcb6160c 100644 --- a/template/oj/problem/problem.html +++ b/template/oj/problem/problem.html @@ -21,12 +21,12 @@
-

第一行包括两个数n,k

+

{{ problem.input_description }}

-

第一行包括两个数n,k

+

{{ problem.output_description }}k

{% for item in samples %}
@@ -45,7 +45,7 @@
- {% if problem.hind %} + {% if problem.hint %}