From 59ee24de45772397d83d6aa89ebad160e3b6126b Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Fri, 14 Aug 2015 10:23:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=8F=90=E4=BA=A4=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E3=80=81=E6=8F=90=E4=BA=A4=E5=88=97=E8=A1=A8=E5=92=8C?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E7=9A=84=E5=90=8E=E5=8F=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oj/local_settings.py | 13 +- oj/urls.py | 4 +- static/src/js/app/oj/problem/problem.js | 2 +- static/src/js/utils/bs_alert.js | 12 +- submission/views.py | 28 ++++- template/admin/admin.html | 18 +-- template/admin_base.html | 120 ------------------- template/oj/problem/_problem_header.html | 7 ++ template/oj/problem/my_submission.html | 57 +++++++++ template/oj/problem/my_submissions_list.html | 96 +++++++-------- template/oj/problem/problem.html | 9 +- template/oj_base.html | 28 +---- template/utils/error.html | 2 +- template/utils/info.html | 2 +- utils/templatetags/__init__.py | 1 + utils/templatetags/submission.py | 42 +++++++ 16 files changed, 202 insertions(+), 239 deletions(-) delete mode 100644 template/admin_base.html create mode 100644 template/oj/problem/_problem_header.html create mode 100644 template/oj/problem/my_submission.html create mode 100644 utils/templatetags/__init__.py create mode 100644 utils/templatetags/submission.py diff --git a/oj/local_settings.py b/oj/local_settings.py index eff9818..7a7249c 100644 --- a/oj/local_settings.py +++ b/oj/local_settings.py @@ -13,18 +13,17 @@ DATABASES = { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 'CONN_MAX_AGE': 0.3, - }, - 'mongodb': { - 'HOST': '127.0.0.1', - 'USERNAME': 'root', - 'PASSWORD': 'root', - 'PORT': 27017 } } +mongodb_setting = { + 'HOST': '127.0.0.1', + 'USERNAME': 'root', + 'PASSWORD': 'root', + 'PORT': 27017 +} DEBUG = True # 同理 这是 web 服务器的上传路径 TEST_CASE_DIR = "/Users/virusdefender/Desktop/test_case/" - diff --git a/oj/urls.py b/oj/urls.py index 78791d5..e2fd51c 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/$', "submission.views.problem_my_submissions_list_page", + url(r'^problem/(?P\d+)/my_submissions/$', "submission.views.problem_my_submissions_list_page", name="problem_my_submissions_page"), - url(r'^my_solution/(?P\w+)/$', "submission.views.my_submission", name="my_submission_page"), + url(r'^my_submission/(?P\w+)/$', "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/static/src/js/app/oj/problem/problem.js b/static/src/js/app/oj/problem/problem.js index 141405a..abcf39c 100644 --- a/static/src/js/app/oj/problem/problem.js +++ b/static/src/js/app/oj/problem/problem.js @@ -49,7 +49,7 @@ require(["jquery", "code_mirror", "csrf", "bs_alert"], function ($, code_mirror, if (!data.result) { html += "CPU time: " + data.accepted_answer_info.time + "ms   "; } - html += ('查看详情 '); + html += ('查看详情 '); return html; } diff --git a/static/src/js/utils/bs_alert.js b/static/src/js/utils/bs_alert.js index b35f06d..547b919 100644 --- a/static/src/js/utils/bs_alert.js +++ b/static/src/js/utils/bs_alert.js @@ -1,7 +1,17 @@ define("bs_alert", ["jquery", "bootstrap"], function($){ function bs_alert(content){ + if(!$("#alert-modal").length) { + var html = ''; + $("body").append(html); + } $("#modal-text").html(content); - $("#modal").modal(); + $("#alert-modal").modal(); } return bs_alert; }); \ No newline at end of file diff --git a/submission/views.py b/submission/views.py index 72a1f4a..0a923e0 100644 --- a/submission/views.py +++ b/submission/views.py @@ -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") \ No newline at end of file +@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}) \ No newline at end of file diff --git a/template/admin/admin.html b/template/admin/admin.html index 69aba41..d5a0e18 100644 --- a/template/admin/admin.html +++ b/template/admin/admin.html @@ -124,23 +124,7 @@ - + diff --git a/template/admin_base.html b/template/admin_base.html deleted file mode 100644 index 86cf7e2..0000000 --- a/template/admin_base.html +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - 在线评测系统 - 后台管理 - - - {% block css_block %}{% endblock %} - - - - - - - - - - - - - - - - - - -
-
- -
- -
- - - - {% block body %}{% endblock %} - -
-
- - - - - - - -{% block js_block %}{% endblock %} - - - - - \ No newline at end of file diff --git a/template/oj/problem/_problem_header.html b/template/oj/problem/_problem_header.html new file mode 100644 index 0000000..82d118f --- /dev/null +++ b/template/oj/problem/_problem_header.html @@ -0,0 +1,7 @@ + +

{{ problem.title }}

+ +

发布时间 : {{ problem.create_time }}   + 时间限制 : {{ problem.time_limit }}ms   + 内存限制 : {{ problem.memory_limit }}M +

\ No newline at end of file diff --git a/template/oj/problem/my_submission.html b/template/oj/problem/my_submission.html new file mode 100644 index 0000000..e7f6ce4 --- /dev/null +++ b/template/oj/problem/my_submission.html @@ -0,0 +1,57 @@ +{% extends 'oj_base.html' %} +{% block css_block %} + +{% endblock %} +{% block body %} + {% load submission %} +
+ + {% include "oj/problem/_problem_header.html" %} +
+
+

运行结果 : + {{ submission.result|translate_result }} + +

+ {% ifequal submission.result 0 %} +

时间 : {{ submission.accepted_answer_info.time }}ms 语言 : + {{ submission.language|translate_language }} +

+ {% endifequal %} + {% ifequal submission.result 4 %} +

{{ submission.info }}

+ {% endifequal %} +

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

+
+
+
+ +
+
+ +{% endblock %} +{% block js_block %} + +{% endblock %} \ No newline at end of file diff --git a/template/oj/problem/my_submissions_list.html b/template/oj/problem/my_submissions_list.html index cc9e138..b1c6388 100644 --- a/template/oj/problem/my_submissions_list.html +++ b/template/oj/problem/my_submissions_list.html @@ -3,62 +3,48 @@ {% block body %} {% load submission %} -
- -

Battle Over Cities - Hard Version

+
+ +

{{ problem.title }}

-

cpu: 1000ms 内存: 256M

- - - - - - - - - - - - {% for item in submissions %} - {% ifequal item.result 0 %} - - {% else %} - {% ifequal item.result 8 %} - +

发布时间: {{ problem.create_time }}   + 时间限制: {{ problem.time_limit }}ms   + 内存限制: {{ problem.memory_limit }}M

+
#提交时间结果运行时间语言
+ + + + + + + + + + + {% for item in submissions %} + + + + + - {% endifequal %} + -- + {% endif %} + + + + {% endfor %} - {% endifequal %} - - - - - - - {% endfor %} - - -
#提交时间结果运行时间语言
{{ forloop.counter }}{{ item.create_time }}{{ item.result|translate_result }} + {% if item.accepted_answer_info.time %} + {{ item.accepted_answer_info.time }}ms {% else %} -
+ {{ item.language|translate_language }} +
{{ forloop.counter }}{{ item.create_time }}{{ item.result|translate_result }} - {% if item.accepted_answer_info.time %} - {{ item.accepted_answer_info.time }}ms - {% else %} - -- - {% endif %} - - {% ifequal item.language 1 %} - C - {% else %} - {% ifequal item.language 2 %} - C++ - {% else %} - Java - {% endifequal %} - {% endifequal %} -
-
+ + +
{% endblock %} \ No newline at end of file diff --git a/template/oj/problem/problem.html b/template/oj/problem/problem.html index 1764db2..2d8ddbb 100644 --- a/template/oj/problem/problem.html +++ b/template/oj/problem/problem.html @@ -5,12 +5,9 @@ -

{{ problem.title }}

- -

发布时间: {{ problem.create_time }} CPU: {{ problem.time_limit }}ms - 内存: {{ problem.memory_limit }}M

+ {% include "oj/problem/_problem_header.html" %}
@@ -93,7 +90,7 @@
-
+
{% endblock %} diff --git a/template/oj_base.html b/template/oj_base.html index 0cfcf82..4a17157 100644 --- a/template/oj_base.html +++ b/template/oj_base.html @@ -8,13 +8,13 @@ 在线评测系统 - - {% block css_block %}{% endblock %} - - + + + {% block css_block %}{% endblock %} + @@ -47,7 +47,7 @@
  • 比赛
  • 关于
  • - {% if not request.user.is_authenticated %} + {% if request.user.is_authenticated %}