修改题目前端样式

This commit is contained in:
virusdefender 2015-08-13 20:29:11 +08:00
parent 2731bc9249
commit 58f9014688
6 changed files with 55 additions and 30 deletions

View File

@ -50,9 +50,9 @@ urlpatterns = [
url(r'^api/admin/problem/$', ProblemAdminAPIView.as_view(), name="problem_admin_api"), 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/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'^api/admin/tag/$', ProblemTagAdminAPIView.as_view(), name="problem_tag_admin_api"),
url(r'^problem/(?P<problem_id>\d+)/my_solutions/', "problem.views.problem_my_solutions_list_page", url(r'^problem/(?P<problem_id>\d+)/my_solutions/', "submission.views.problem_my_submissions_list_page",
name="problem_my_solutions_page"), name="problem_my_submissions_page"),
url(r'^my_solution/(?P<solution_id>\d+)/$', "problem.views.my_solution", name="my_solution_page"), url(r'^my_solution/(?P<solution_id>\d+)/$', "submission.views.my_submission", name="my_submission_page"),
url(r'^api/admin/join_group_request/$', JoinGroupRequestAdminAPIView.as_view(), url(r'^api/admin/join_group_request/$', JoinGroupRequestAdminAPIView.as_view(),
name="join_group_request_admin_api"), name="join_group_request_admin_api"),

View File

@ -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 = [
]

View File

@ -47,15 +47,6 @@ def problem_page(request, problem_id):
return render(request, "oj/problem/problem.html", {"problem": problem, "samples": json.loads(problem.samples)}) 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): class ProblemAdminAPIView(APIView):
def post(self, request): def post(self, request):
""" """
@ -197,7 +188,7 @@ class TestCaseUploadAPIView(APIView):
os.mkdir(test_case_dir) os.mkdir(test_case_dir)
for name in l: for name in l:
f = open(test_case_dir + name, "wb") 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() f.close()
l.sort() l.sort()

View File

@ -25,8 +25,7 @@ require(["jquery", "code_mirror", "csrf", "bs_alert"], function ($, code_mirror,
} }
function get_result_html(result) { function get_result_html(data) {
console.log(result);
// 0 结果正确 1 运行错误 2 超时 3 超内存 4 编译错误 // 0 结果正确 1 运行错误 2 超时 3 超内存 4 编译错误
// 5 格式错误 6 结果错误 7 系统错误 8 等待判题 // 5 格式错误 6 结果错误 7 系统错误 8 等待判题
var results = { var results = {
@ -42,14 +41,16 @@ require(["jquery", "code_mirror", "csrf", "bs_alert"], function ($, code_mirror,
}; };
var html = '<div class="alert alert-' + var html = '<div class="alert alert-' +
results[result].alert_class + ' result"' + results[data.result].alert_class + ' result"' +
' role="alert">' + ' role="alert">' +
'<div class="alert-link">' + '<div class="alert-link">' +
results[result].message + results[data.result].message +
'!&nbsp;&nbsp;&nbsp;&nbsp; ' + '!&nbsp;&nbsp; ';
'<a href="#">查看详情</a> ' + if (!data.result) {
'</div> </div>'; html += "CPU time: " + data.accepted_answer_info.time + "ms &nbsp;&nbsp;";
console.log(html); }
html += ('<a href="/submission/' + submission_id + '/" target="_blank">查看详情</a></div> </div>');
return html; return html;
} }
@ -67,7 +68,7 @@ require(["jquery", "code_mirror", "csrf", "bs_alert"], function ($, code_mirror,
} }
else { else {
hide_loading(); hide_loading();
$("#result").html(get_result_html(data.data.result)); $("#result").html(get_result_html(data.data));
} }
} }
else { else {
@ -84,7 +85,7 @@ require(["jquery", "code_mirror", "csrf", "bs_alert"], function ($, code_mirror,
show_loading(); show_loading();
if(!code){ if(!code.trim()){
bs_alert("请填写代码!"); bs_alert("请填写代码!");
hide_loading(); hide_loading();
return false; return false;

View File

@ -1,4 +1,5 @@
# coding=utf-8 # coding=utf-8
import datetime
import pymongo import pymongo
from bson.objectid import ObjectId from bson.objectid import ObjectId
@ -16,12 +17,13 @@ from utils.shortcuts import serializer_invalid_response, error_response, success
from .serializers import CreateSubmissionSerializer from .serializers import CreateSubmissionSerializer
class SubmissionnAPIView(APIView): def _create_mondodb_connection():
def _create_mondodb_connection(self):
mongodb_setting = settings.DATABASES["mongodb"] mongodb_setting = settings.DATABASES["mongodb"]
connection = pymongo.MongoClient(host=mongodb_setting["HOST"], port=mongodb_setting["PORT"]) connection = pymongo.MongoClient(host=mongodb_setting["HOST"], port=mongodb_setting["PORT"])
return connection["oj"]["oj_submission"] return connection["oj"]["oj_submission"]
class SubmissionnAPIView(APIView):
@login_required @login_required
def post(self, request): def post(self, request):
""" """
@ -35,6 +37,7 @@ class SubmissionnAPIView(APIView):
# data["language"] = int(data["language"]) # data["language"] = int(data["language"])
data["user_id"] = request.user.id data["user_id"] = request.user.id
data["result"] = result["waiting"] data["result"] = result["waiting"]
data["create_time"] = datetime.datetime.now()
try: try:
problem = Problem.objects.get(id=data["problem_id"]) problem = Problem.objects.get(id=data["problem_id"])
except Problem.DoesNotExist: except Problem.DoesNotExist:
@ -53,8 +56,23 @@ class SubmissionnAPIView(APIView):
submission_id = request.GET.get("submission_id", None) submission_id = request.GET.get("submission_id", None)
if not submission_id: if not submission_id:
return error_response(u"参数错误") 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: 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: else:
return error_response(u"提交不存在") 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")

View File

@ -21,12 +21,12 @@
<div class="problem-section"> <div class="problem-section">
<label class="problem-label">输入</label> <label class="problem-label">输入</label>
<p class="problem-detail">第一行包括两个数n,k</p> <p class="problem-detail">{{ problem.input_description }}</p>
</div> </div>
<div class="problem-section"> <div class="problem-section">
<label class="problem-label">输出</label> <label class="problem-label">输出</label>
<p class="problem-detail">第一行包括两个数n,k</p> <p class="problem-detail">{{ problem.output_description }}k</p>
</div> </div>
{% for item in samples %} {% for item in samples %}
<div class="problem-section"> <div class="problem-section">
@ -45,7 +45,7 @@
<div> <div>
<button type="button" id="show-more-btn" class="btn btn-info btn-sm">查看隐藏信息</button> <button type="button" id="show-more-btn" class="btn btn-info btn-sm">查看隐藏信息</button>
</div> </div>
{% if problem.hind %} {% if problem.hint %}
<div class="problem-section hide"> <div class="problem-section hide">
<label class="problem-label">提示</label> <label class="problem-label">提示</label>