Merge branch 'dev' into virusdefender-dev

* dev: (38 commits)
  with open()  as 语句添加try&except,返回上传错误
  添加缓存用redis的配置
  [后台-前端]修改添加比赛,编辑比赛页面,添加封榜功能(在页面中被称作实时排名)若设置比赛非实时排名那么前端rank页面缓存将停止刷新,从而实现封榜功能[CI SKIP]
  migrate:contest.models字段改名----show_rank => real_time_rank
  添加控制比赛排名更新的字段
  统一创建比赛,编辑比赛的时候小组可见的交互逻辑和界面[CI SKIP]
  修正server_setting中typo和urls里别扭的拼写
  修改.gitignore,忽略富文本编辑器上传的图片,删掉刚刚不小心commit的图片[CI SKIP]
  新建存放富文本编辑器上传的图片的文件夹[CI SKIP]
  添加了富文本编辑器上传图片的功能,上传路径在setting_loacl和server里暂时在static/src/upload_image/
  修复冲突,忘记去掉冲突标志了。。。
  [后台-前端]主要修改了添加比赛和修改比赛的部分,去掉比赛结束前开放排名这一选项,添加封榜时间字段[CI SKIP]
  [后台-前端]去掉了比赛中的是否开放排名选 项,天加封榜时间字段[CI SKIP]
  添加前台比赛提交列表中管理员可见比赛提交详情
  刚刚不小心把两个文件粘一起了,原来的忘清了。。。
  修复超级管理员比赛提交页面的样式“
  合并dev,添加管理员在前台可见比赛所有提交详情,修改措辞,修改提示形式,以便于提交列表筛选功能的使用
  修复题目,比赛题目列表里描述和提示的内容没有包裹在 problem-detail里的问题,实际上源代码里他们被包裹在<p clas s='problem-detail'>里但是实际显示的却是在标签外部,不理解.把p改成div就好了~
  其实没有更改,跟origin dev-sxw保持一致,因为刚刚git pull的时候出错了
  修改了宽松判题模式中对超时的处理,否则超时将被判为runTimeError[CI SKIP]
  ...

Conflicts:
	judge/judger/loose_client.py
This commit is contained in:
virusdefender
2015-09-12 21:50:45 +08:00
26 changed files with 711 additions and 403 deletions

1
.gitignore vendored
View File

@@ -58,6 +58,7 @@ log/
static/release/css static/release/css
static/release/js static/release/js
static/release/img static/release/img
static/src/upload_image/*
build.txt build.txt
tmp/ tmp/
test_case/ test_case/

1
Accessories/__init__.py Normal file
View File

@@ -0,0 +1 @@
__author__ = 'root'

74
Accessories/reJudge.py Normal file
View File

@@ -0,0 +1,74 @@
import django
from contest.models import *
from problem.models import *
from submission.models import Submission
import redis
from judge.judger_controller.tasks import judge
from judge.judger_controller.settings import redis_config
django.setup()
def rejudge(submission):
# for submission in submission:
# submission_id = submission.id
# try:
# command = "%s run -t -i --privileged --rm=true " \
# "-v %s:/var/judger/test_case/ " \
# "-v %s:/var/judger/code/ " \
# "%s " \
# "python judge/judger/run.py " \
# "--solution_id %s --time_limit %s --memory_limit %s --test_case_id %s" % \
# (docker_config["docker_path"],
# test_case_dir,
# source_code_dir,
# docker_config["image_name"],
# submission_id, str(time_limit), str(memory_limit), test_case_id)
# subprocess.call(command, shell=docker_config["shell"])
# except Exception as e:
# print e
return
def easy_rejudge(submissions, map_table, user_id, contest_id=None):
try:
user = User.objects.get(pk=user_id)
except User.DoesNotExist:
print "User.DoesNotExist!"
return
problemDict = {}
for oldSubmission in submission:
problem_id = map_table[oldSubmission.problem_id]
if problem_id in problemDict:
problem = problemDict[problem_id]
else:
try:
p = Problem.objects.get(pk=problem_id)
except Problem.DoesNotExist:
print " Problem.DoesNotExist!" + str(problem_id)
continue
problem = p
problemDict[problem_id] = p
submission = Submission.objects.create(
user_id=user_id,
language=oldSubmission.language,
code=oldSubmission.code,
contest_id=contest_id,
problem_id=problem_id,
originResult=oldSubmission.result
)
try:
judge.delay(submission.id, problem.time_limit, problem.memory_limit, problem.test_case_id)
except Exception:
print "error!"
continue
r = redis.Redis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"])
r.incr("judge_queue_length")
return

61
Accessories/utils.py Executable file
View File

@@ -0,0 +1,61 @@
import django
from contest.models import *
from problem.models import *
django.setup()
def add_exist_problem_to_contest(problems, contest_id):
try:
contest = Contest.objects.get(pk=contest_id)
except Contest.DoesNotExist:
print "Contest Doesn't Exist!"
return
i = 1
for problem in problems:
print "Add the problem:"
print problem.title
print "The sort Index is" + str(i) + " You Can modify it latter as you like~"
ContestProblem.objects.create(contest=contest, sort_index=str(i),
title=problem.title, description=problem.description,
input_description=problem.input_description,
output_description=problem.output_description,
samples=problem.samples,
test_case_id=problem.test_case_id,
hint=problem.hint,
created_by=problem.created_by,
time_limit=problem.time_limit,
memory_limit=problem.memory_limit)
i += 1
return
def add_contest_problem_to_problem(contest_id):
try:
contest = Contest.objects.get(pk=contest_id)
except Contest.DoesNotExist:
print "Contest Doesn't Exist!"
return
#Get all problems in this contest
problems = ContestProblem.objects.filter(contest=contest)
#get a tag
try:
tag = ProblemTag.objects.get(name=contest.title)
except ProblemTag.DoesNotExist:
tag = ProblemTag.objects.create(name=contest.title)
#for each problem
for problem in problems:
print "Add problem to problem list:"
print problem.title
p = Problem.objects.create(title=problem.title,
description=problem.description,
input_description=problem.input_description,
output_description=problem.output_description,
samples=problem.samples,
test_case_id=problem.test_case_id,
hint=problem.hint,
created_by=problem.created_by,
time_limit=problem.time_limit,
memory_limit=problem.memory_limit,
visible = False,
difficulty = 0,
source = contest.title)
p.tags.add(tag)
return

View File

@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('contest', '0007_contestsubmission_ac_time'),
]
operations = [
migrations.RenameField(
model_name='contest',
old_name='show_rank',
new_name='real_time_rank',
),
]

View File

@@ -17,8 +17,8 @@ class Contest(models.Model):
description = models.TextField() description = models.TextField()
# 比赛模式0 即为是acm模式1 即为是按照总的 ac 题目数量排名模式 # 比赛模式0 即为是acm模式1 即为是按照总的 ac 题目数量排名模式
mode = models.IntegerField() mode = models.IntegerField()
# 是否显示排名结果 # 是否显示实时排名结果
show_rank = models.BooleanField() real_time_rank = models.BooleanField()
# 是否显示别人的提交记录 # 是否显示别人的提交记录
show_user_submission = models.BooleanField() show_user_submission = models.BooleanField()
# 只能超级管理员创建公开赛,管理员只能创建小组内部的比赛 # 只能超级管理员创建公开赛,管理员只能创建小组内部的比赛

View File

@@ -353,8 +353,8 @@ def contest_list_page(request, page=1):
# 筛选我能参加的比赛 # 筛选我能参加的比赛
join = request.GET.get("join", None) join = request.GET.get("join", None)
if join: if request.user.is_authenticated and join:
contests = contests.filter(Q(contest_type__in=[PUBLIC_CONTEST, PASSWORD_PUBLIC_CONTEST]) | Q(groups__in=request.user.group_set.all())). \ contests = contests.filter(Q(contest_type__in=[1, 2]) | Q(groups__in=request.user.group_set.all())). \
filter(end_time__gt=datetime.datetime.now(), start_time__lt=datetime.datetime.now()) filter(end_time__gt=datetime.datetime.now(), start_time__lt=datetime.datetime.now())
paginator = Paginator(contests, 20) paginator = Paginator(contests, 20)

View File

@@ -119,6 +119,14 @@ def contest_problem_submissions_list_page(request, contest_id, page=1):
next_page = current_page.next_page_number() next_page = current_page.next_page_number()
except Exception: except Exception:
pass pass
# 如果该用户是超级管理员那么他可以查看所有的提交记录详情
if request.user.admin_type > 1:
return render(request, "oj/contest/submissions_list_admin.html",
{"submissions": current_page, "page": int(page),
"previous_page": previous_page, "next_page": next_page, "start_id": int(page) * 20 - 20,
"contest": contest})
return render(request, "oj/contest/submissions_list.html", return render(request, "oj/contest/submissions_list.html",
{"submissions": current_page, "page": int(page), {"submissions": current_page, "page": int(page),
"previous_page": previous_page, "next_page": next_page, "start_id": int(page) * 20 - 20, "previous_page": previous_page, "next_page": next_page, "start_id": int(page) * 20 - 20,

View File

@@ -25,9 +25,17 @@ DATABASES = {
} }
} }
REDIS_CACHE = {
"host": "121.42.32.129",
"port": 6379,
"db": 1
}
DEBUG = True DEBUG = True
# 同理 这是 web 服务器的上传路径 # 同理 这是 web 服务器的上传路径
TEST_CASE_DIR = os.path.join(BASE_DIR, 'test_case/') TEST_CASE_DIR = os.path.join(BASE_DIR, 'test_case/')
ALLOWED_HOSTS = [] ALLOWED_HOSTS = []
IMAGE_UPLOAD_DIR = os.path.join(BASE_DIR, 'static/src/upload_image/')

View File

@@ -29,9 +29,17 @@ DATABASES = {
} }
} }
REDIS_CACHE = {
"host": "127.0.0.1",
"port": 6379,
"db": 1
}
DEBUG = True DEBUG = True
# 同理 这是 web 服务器的上传路径 # 同理 这是 web 服务器的上传路径
TEST_CASE_DIR = '/root/test_case/' TEST_CASE_DIR = '/root/test_case/'
ALLOWED_HOSTS = ['*'] ALLOWED_HOSTS = ['*']
IMAGE_UPLOAD_DIR = '/var/mnt/source/OnlineJudge/static/src/upload_image/'

View File

@@ -19,6 +19,7 @@ from problem.views import TestCaseUploadAPIView, ProblemTagAdminAPIView, Problem
from submission.views import SubmissionAPIView, SubmissionAdminAPIView, SubmissionShareAPIView from submission.views import SubmissionAPIView, SubmissionAdminAPIView, SubmissionShareAPIView
from contest_submission.views import ContestSubmissionAPIView, ContestSubmissionAdminAPIView from contest_submission.views import ContestSubmissionAPIView, ContestSubmissionAdminAPIView
from monitor.views import QueueLengthMonitorAPIView from monitor.views import QueueLengthMonitorAPIView
from utils.views import SimditorImageUploadAPIView
from contest_submission.views import contest_problem_my_submissions_list_page from contest_submission.views import contest_problem_my_submissions_list_page
@@ -53,6 +54,7 @@ urlpatterns = [
url(r'^api/submission/$', SubmissionAPIView.as_view(), name="submission_api"), url(r'^api/submission/$', SubmissionAPIView.as_view(), name="submission_api"),
url(r'^api/group_join/$', JoinGroupAPIView.as_view(), name="group_join_api"), url(r'^api/group_join/$', JoinGroupAPIView.as_view(), name="group_join_api"),
url(r'^api/admin/upload_image/$', SimditorImageUploadAPIView.as_view(), name="simditor_upload_image"),
url(r'^api/admin/announcement/$', AnnouncementAdminAPIView.as_view(), name="announcement_admin_api"), url(r'^api/admin/announcement/$', AnnouncementAdminAPIView.as_view(), name="announcement_admin_api"),
url(r'^api/admin/contest/$', ContestAdminAPIView.as_view(), name="contest_admin_api"), url(r'^api/admin/contest/$', ContestAdminAPIView.as_view(), name="contest_admin_api"),
url(r'^api/admin/user/$', UserAdminAPIView.as_view(), name="user_admin_api"), url(r'^api/admin/user/$', UserAdminAPIView.as_view(), name="user_admin_api"),
@@ -112,5 +114,6 @@ urlpatterns = [
url(r'^help/$', TemplateView.as_view(template_name="utils/help.html"), name="help_page"), url(r'^help/$', TemplateView.as_view(template_name="utils/help.html"), name="help_page"),
url(r'^api/submission/share/$', SubmissionShareAPIView.as_view(), name="submission_share_api"), url(r'^api/submission/share/$', SubmissionShareAPIView.as_view(), name="submission_share_api"),
url(r'^captcha/$', "utils.captcha.views.show_captcha", name="show_captcha"), url(r'^captcha/$', "utils.captcha.views.show_captcha", name="show_captcha"),
] ]

View File

@@ -147,9 +147,12 @@ class TestCaseUploadAPIView(APIView):
f = request.FILES["file"] f = request.FILES["file"]
tmp_zip = "/tmp/" + rand_str() + ".zip" tmp_zip = "/tmp/" + rand_str() + ".zip"
try:
with open(tmp_zip, "wb") as test_case_zip: with open(tmp_zip, "wb") as test_case_zip:
for chunk in f: for chunk in f:
test_case_zip.write(chunk) test_case_zip.write(chunk)
except IOError:
return error_response(u"上传错误,写入临时目录失败")
test_case_file = zipfile.ZipFile(tmp_zip, 'r') test_case_file = zipfile.ZipFile(tmp_zip, 'r')
name_list = test_case_file.namelist() name_list = test_case_file.namelist()
@@ -254,7 +257,7 @@ def problem_list_page(request, page=1):
tag = ProblemTag.objects.get(name=tag_text) tag = ProblemTag.objects.get(name=tag_text)
except ProblemTag.DoesNotExist: except ProblemTag.DoesNotExist:
return error_page(request, u"标签不存在") return error_page(request, u"标签不存在")
problems = tag.problem_set.all() problems = tag.problem_set.all().filter(visible=True)
paginator = Paginator(problems, 20) paginator = Paginator(problems, 20)
try: try:

View File

@@ -1,3 +1,13 @@
/** /**
* Created by virusdefender on 8/25/15. * Created by virusdefender on 8/25/15.
*/ */
fis.match('*.{js,css,png,gif}', {
useHash: true // 开启 md5 戳
});
fis.config.set(
'roadmap.path',
[{reg:'*.html',isHtmlLike : true}
])
;

View File

@@ -2,7 +2,6 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
"validator"], "validator"],
function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) { function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) {
//avalon.vmodels.add_contest = null;
$("#add-contest-form").validator().on('submit', function (e) { $("#add-contest-form").validator().on('submit', function (e) {
if (!e.isDefaultPrevented()) { if (!e.isDefaultPrevented()) {
e.preventDefault(); e.preventDefault();
@@ -11,31 +10,38 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
description: vm.description, description: vm.description,
mode: vm.mode, mode: vm.mode,
contest_type: 0, contest_type: 0,
show_rank: vm.showRank, real_time_rank: vm.realTimeRank,
show_user_submission: vm.showSubmission, show_user_submission: vm.showSubmission,
start_time: vm.startTime, start_time: vm.startTime,
end_time: vm.endTime, end_time: vm.endTime,
visible: false visible: false
}; };
if (vm.choseGroupList.length == 0) {
bsAlert("你没有选择参赛用户!"); var selectedGroups = [];
return false; if (!vm.isGlobal) {
for (var i = 0; i < vm.allGroups.length; i++) {
if (vm.allGroups[i].isSelected) {
selectedGroups.push(vm.allGroups[i].id);
} }
if (vm.choseGroupList[0].id == 0) { //everyone | public contest }
ajaxData.groups = selectedGroups;
}
else {
if (vm.password) { if (vm.password) {
ajaxData.password = vm.password; ajaxData.password = vm.password;
ajaxData.contest_type = 2; ajaxData.contest_type = 2;
} }
else{ else
ajaxData.contest_type = 1; ajaxData.contest_type = 1;
} }
if (!vm.isGlobal && !selectedGroups.length) {
bsAlert("你没有选择参赛用户!");
return false;
} }
else { // Add groups info if (vm.editDescription == "") {
ajaxData.groups = []; bsAlert("比赛描述不能为空!");
for (var i = 0; vm.choseGroupList[i]; i++) return false;
ajaxData.groups.push(parseInt(vm.choseGroupList[i].id))
} }
$.ajax({ // Add contest $.ajax({ // Add contest
beforeSend: csrfTokenHeader, beforeSend: csrfTokenHeader,
url: "/api/admin/contest/", url: "/api/admin/contest/",
@@ -51,14 +57,12 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
vm.startTime = ""; vm.startTime = "";
vm.endTime = ""; vm.endTime = "";
vm.password = ""; vm.password = "";
vm.mode = ""; vm.mode = "0";
vm.showRank = false; vm.showSubmission = true;
vm.showSubmission = false;
vm.group = "-1";
vm.groupList = [];
vm.choseGroupList = [];
vm.passwordUsable = false;
location.hash = "#contest/contest_list"; location.hash = "#contest/contest_list";
vm.isGlobal = true;
vm.allGroups = [];
vm.showGlobalViewRadio = true;
} }
else { else {
bsAlert(data.data); bsAlert(data.data);
@@ -80,62 +84,42 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
startTime: "", startTime: "",
endTime: "", endTime: "",
password: "", password: "",
mode: "", mode: "0",
showRank: false, showSubmission: true,
showSubmission: false, isGlobal: true,
group: "-1", allGroups: [],
groupList: [], showGlobalViewRadio: true,
choseGroupList: [], realTimeRank: true
passwordUsable: false,
addGroup: function() {
if (vm.group == -1) return;
if (vm.groupList[vm.group].id == 0){
vm.passwordUsable = true;
vm.choseGroupList = [];
for (var key in vm.groupList){
vm.groupList[key].chose = true;
}
}
vm.groupList[vm.group]. chose = true;
vm.choseGroupList.push({name:vm.groupList[vm.group].name, index:vm.group, id:vm.groupList[vm.group].id});
vm.group = -1;
},
removeGroup: function(groupIndex){
if (vm.groupList[vm.choseGroupList[groupIndex].index].id == 0){
vm.passwordUsable = false;
for (key in vm.groupList){
vm.groupList[key].chose = false;
}
}
vm.groupList[vm.choseGroupList[groupIndex].index].chose = false;
vm.choseGroupList.remove(vm.choseGroupList[groupIndex]);
}
}); });
$.ajax({ // Get current user type $.ajax({
url: "/api/user/", url: "/api/user/",
method: "get", method: "get",
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
if (!data.code) { if (!data.code) {
if (data.data.admin_type == 2) { // Is super user var admin_type = data.data.admin_type;
vm.isGlobal = true; if (data.data.admin_type == 1) {
vm.groupList.push({id:0,name:"所有人",chose:false}); vm.isGlobal = false;
vm.showGlobalViewRadio = false;
} }
$.ajax({ // Get the group list of current user }
beforeSend: csrfTokenHeader, $.ajax({
url: "/api/admin/group/", url: "/api/admin/group/",
method: "get", method: "get",
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
if (!data.code) { if (!data.code) {
if (!data.data.length) { if (!data.data.length) {
if (admin_type != 2)
bsAlert("您的用户权限只能创建小组内比赛,但是您还没有创建过小组");
return; return;
} }
for (var i = 0; i < data.data.length; i++) { for (var i = 0; i < data.data.length; i++) {
var item = data.data[i]; var item = data.data[i];
item["chose"] = false; item["isSelected"] = false;
vm.groupList.push(item); vm.allGroups.push(item);
} }
} }
else { else {
@@ -144,7 +128,6 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
} }
}); });
} }
}
}); });
avalon.scan(); avalon.scan();

View File

@@ -11,13 +11,31 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
description: vm.editDescription, description: vm.editDescription,
mode: vm.editMode, mode: vm.editMode,
contest_type: 0, contest_type: 0,
show_rank: vm.editShowRank, real_time_rank: vm.editRealTimeRank,
show_user_submission: vm.editShowSubmission, show_user_submission: vm.editShowSubmission,
start_time: vm.editStartTime, start_time: vm.editStartTime,
end_time: vm.editEndTime, end_time: vm.editEndTime,
visible: vm.editVisible visible: vm.editVisible
}; };
if (vm.choseGroupList.length == 0) {
var selectedGroups = [];
if (!vm.isGlobal) {
for (var i = 0; i < vm.allGroups.length; i++) {
if (vm.allGroups[i].isSelected) {
selectedGroups.push(vm.allGroups[i].id);
}
}
ajaxData.groups = selectedGroups;
}
else {
if (vm.password) {
ajaxData.password = vm.editPassword;
ajaxData.contest_type = 2;
}
else
ajaxData.contest_type = 1;
}
if (!vm.isGlobal && !selectedGroups.length) {
bsAlert("你没有选择参赛用户!"); bsAlert("你没有选择参赛用户!");
return false; return false;
} }
@@ -25,22 +43,8 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
bsAlert("比赛描述不能为空!"); bsAlert("比赛描述不能为空!");
return false; return false;
} }
if (vm.choseGroupList[0].id == 0) { //everyone | public contest
if (vm.editPassword) {
ajaxData.password = vm.editPassword;
ajaxData.contest_type = 2;
}
else{
ajaxData.contest_type = 1;
}
}
else { // Add groups info
ajaxData.groups = [];
for (var i = 0; vm.choseGroupList[i]; i++)
ajaxData.groups.push(parseInt(vm.choseGroupList[i].id))
}
$.ajax({ // Add contest $.ajax({ // modify contest info
beforeSend: csrfTokenHeader, beforeSend: csrfTokenHeader,
url: "/api/admin/contest/", url: "/api/admin/contest/",
dataType: "json", dataType: "json",
@@ -71,10 +75,6 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
vm.nextPage = 0; vm.nextPage = 0;
vm.page = 1; vm.page = 1;
vm.totalPage = 1; vm.totalPage = 1;
vm.group= "-1";
vm.groupList= [];
vm.choseGroupList= [];
vm.passwordUsable= false;
vm.keyword = ""; vm.keyword = "";
vm.editingContestId = 0; vm.editingContestId = 0;
vm.editTitle = ""; vm.editTitle = "";
@@ -84,12 +84,10 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
vm.editStartTime = ""; vm.editStartTime = "";
vm.editEndTime = ""; vm.editEndTime = "";
vm.editMode = ""; vm.editMode = "";
vm.editShowRank= false;
vm.editShowSubmission = false; vm.editShowSubmission = false;
vm.editProblemList= [];
vm.editVisible = false; vm.editVisible = false;
vm.editChoseGroupList= [];
vm.editingProblemContestIndex = 0; vm.editingProblemContestIndex = 0;
vm.editRealTimeRank = true;
} }
else { else {
var vm = avalon.define({ var vm = avalon.define({
@@ -100,10 +98,6 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
page: 1, page: 1,
totalPage: 1, totalPage: 1,
showVisibleOnly: false, showVisibleOnly: false,
group: "-1",
groupList: [],
choseGroupList: [],
passwordUsable: false,
keyword: "", keyword: "",
editingContestId: 0, editingContestId: 0,
editTitle: "", editTitle: "",
@@ -113,12 +107,14 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
editStartTime: "", editStartTime: "",
editEndTime: "", editEndTime: "",
editMode: "", editMode: "",
editShowRank: false,
editShowSubmission: false, editShowSubmission: false,
editProblemList: [],
editVisible: false, editVisible: false,
editChoseGroupList: [], editRealTimeRank: true,
editingProblemContestIndex: 0, editingProblemContestIndex: 0,
isGlobal: true,
allGroups: [],
showGlobalViewRadio: true,
getNext: function () { getNext: function () {
if (!vm.nextPage) if (!vm.nextPage)
return; return;
@@ -153,32 +149,26 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
vm.editEndTime = vm.contestList[contestId - 1].end_time.substring(0, 16).replace("T", " "); vm.editEndTime = vm.contestList[contestId - 1].end_time.substring(0, 16).replace("T", " ");
vm.editMode = vm.contestList[contestId - 1].mode; vm.editMode = vm.contestList[contestId - 1].mode;
vm.editVisible = vm.contestList[contestId - 1].visible; vm.editVisible = vm.contestList[contestId - 1].visible;
vm.editRealTimeRank = vm.contestList[contestId - 1].real_time_rank;
if (vm.contestList[contestId - 1].contest_type == 0) { //contest type == 0, contest in group if (vm.contestList[contestId - 1].contest_type == 0) { //contest type == 0, contest in group
//Clear the choseGroupList vm.isGlobal = false;
while (vm.choseGroupList.length) { for (var i = 0; i < vm.allGroups.length; i++) {
vm.removeGroup(0); vm.allGroups[i].isSelected = false;
} }
for (var i = 0; i < vm.contestList[contestId - 1].groups.length; i++) { for (var i = 0; i < vm.contestList[contestId - 1].groups.length; i++) {
var id = parseInt(vm.contestList[contestId - 1].groups[i]); var id = parseInt(vm.contestList[contestId - 1].groups[i]);
var index = 0;
for (; vm.groupList[index]; index++) { for (var index = 0; vm.allGroups[index]; index++) {
if (vm.groupList[index].id == id) if (vm.allGroups[index].id == id) {
vm.allGroups[index].isSelected = true;
break; break;
} }
vm.groupList[index].chose = true; }
vm.choseGroupList.push({
name:vm.groupList[index].name,
index:index,
id:id
});
} }
} }
else { else {
vm.group = "0"; vm.isGlobal = true;
vm.addGroup()//vm.editChoseGroupList = [0]; id 0 is for the group of everyone~
} }
vm.editShowRank = vm.contestList[contestId-1].show_rank;
vm.editShowSubmission = vm.contestList[contestId - 1].show_user_submission; vm.editShowSubmission = vm.contestList[contestId - 1].show_user_submission;
editor("#editor").setValue(vm.contestList[contestId - 1].description); editor("#editor").setValue(vm.contestList[contestId - 1].description);
vm.editingProblemContestIndex = 0; vm.editingProblemContestIndex = 0;
@@ -210,30 +200,6 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
vm.editingProblemContestIndex = contestId; vm.editingProblemContestIndex = contestId;
vm.editMode = vm.contestList[contestId - 1].mode; vm.editMode = vm.contestList[contestId - 1].mode;
}, },
addGroup: function() {
if (vm.group == -1) return;
if (vm.groupList[vm.group].id == 0){
vm.passwordUsable = true;
vm.choseGroupList = [];
for (var i = 0; i < vm.groupList.length; i++) {
vm.groupList[i].chose = true;
}
}
vm.groupList[vm.group]. chose = true;
// index of the group is relative. It is related to user
vm.choseGroupList.push({name:vm.groupList[vm.group].name, index:vm.group, id:vm.groupList[vm.group].id});
vm.group = -1;
},
removeGroup: function(groupIndex){
if (vm.groupList[vm.choseGroupList[groupIndex].index].id == 0){
vm.passwordUsable = false;
for (var i = 0; i < vm.groupList.length; i++) {
vm.groupList[i].chose = false;
}
}
vm.groupList[vm.choseGroupList[groupIndex].index].chose = false;
vm.choseGroupList.remove(vm.choseGroupList[groupIndex]);
},
addProblem: function () { addProblem: function () {
vm.$fire("up!showContestProblemPage", 0, vm.contestList[vm.editingProblemContestIndex - 1].id, vm.editMode); vm.$fire("up!showContestProblemPage", 0, vm.contestList[vm.editingProblemContestIndex - 1].id, vm.editMode);
}, },
@@ -293,31 +259,33 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
} }
// Get group list // Get group list
$.ajax({ // Get current user type $.ajax({
url: "/api/user/", url: "/api/user/",
method: "get", method: "get",
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
if (!data.code) { if (!data.code) {
if (data.data.admin_type == 2) { // Is super user var admin_type = data.data.admin_type;
vm.isGlobal = true; if (data.data.admin_type == 1) {
vm.groupList.push({id:0,name:"所有人",chose:false}); vm.isGlobal = false;
vm.showGlobalViewRadio = false;
} }
$.ajax({ // Get the group list of current user }
beforeSend: csrfTokenHeader, $.ajax({
url: "/api/admin/group/", url: "/api/admin/group/",
method: "get", method: "get",
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
if (!data.code) { if (!data.code) {
if (!data.data.length) { if (!data.data.length) {
//this user have no group can use if (admin_type != 2)
bsAlert("您的用户权限只能创建小组内比赛,但是您还没有创建过小组");
return; return;
} }
for (var i = 0; i < data.data.length; i++) { for (var i = 0; i < data.data.length; i++) {
var item = data.data[i]; var item = data.data[i];
item["chose"] = false; item["isSelected"] = false;
vm.groupList.push(item); vm.allGroups.push(item);
} }
} }
else { else {
@@ -326,7 +294,6 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
} }
}); });
} }
}
}); });
}); });

View File

@@ -1,8 +1,9 @@
({ ({
// RequireJS 通过一个相对的路径 baseUrl来加载所有代码。baseUrl通常被设置成data-main属性指定脚本的同级目录。 // RequireJS 通过一个相对的路径 baseUrl来加载所有代码。baseUrl通常被设置成data-main属性指定脚本的同级目录。
baseUrl: "js/", baseUrl: "/static/js/",
// 第三方脚本模块的别名,jquery比libs/jquery-1.11.1.min.js简洁明了 // 第三方脚本模块的别名,jquery比libs/jquery-1.11.1.min.js简洁明了
paths: { paths: {
jquery: "lib/jquery/jquery", jquery: "lib/jquery/jquery",
avalon: "lib/avalon/avalon", avalon: "lib/avalon/avalon",
editor: "utils/editor", editor: "utils/editor",
@@ -37,12 +38,12 @@
webUploader: "lib/webuploader/webuploader", webUploader: "lib/webuploader/webuploader",
"_datetimePicker": "lib/datetime_picker/bootstrap-datetimepicker" "_datetimePicker": "lib/datetime_picker/bootstrap-datetimepicker"
}, },
shim: { shim: {
"bootstrap": {"deps": ['jquery']}, bootstrap: {deps: ["jquery"]},
"_datetimepicker": {"deps": ["jquery"]}, _datetimePicker: {dep: ["jquery"]},
"datetimepicker": {"deps": ["_datetimepicker"]} datetimePicker: {deps: ["_datetimePicker"]},
validator: ["jquery"]
}, },
findNestedDependencies: true, findNestedDependencies: true,
appDir: "../", appDir: "../",

View File

@@ -143,6 +143,16 @@ Uploader = (function(superClass) {
processData: false, processData: false,
contentType: false, contentType: false,
type: 'POST', type: 'POST',
beforeSend: function(){
var name = "csrftoken=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1);
if (c.indexOf(name) != -1) name = c.substring(name.length, c.length);
}
arguments[0].setRequestHeader("X-CSRFToken", name);
},
headers: { headers: {
'X-File-Name': encodeURIComponent(file.name) 'X-File-Name': encodeURIComponent(file.name)
}, },

View File

@@ -8,7 +8,7 @@ define("editor", ["simditor"], function(Simditor){
toolbarFloat: false, toolbarFloat: false,
defaultImage: null, defaultImage: null,
upload: { upload: {
url: "", url: "/api/admin/upload_image/",
params: null, params: null,
fileKey: "image", fileKey: "image",
connectionCount: 3, connectionCount: 3,

View File

@@ -7,7 +7,7 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="form-group"> <div class="form-group">
<input type="text" name="name" class="form-control" ms-duplex="title" <input type="text" name="name" class="form-control" ms-duplex="title"
data-error="请填写比赛名称(名称不能超过50个字)" ms-attr-readonly="contestCreated" required> data-error="请填写比赛名称(名称不能超过50个字)" required>
<div class="help-block with-errors"></div> <div class="help-block with-errors"></div>
</div> </div>
@@ -26,7 +26,6 @@
<div class="form-group"> <div class="form-group">
<input type="text" class="form-control" name="start_time" id="contest_start_time" <input type="text" class="form-control" name="start_time" id="contest_start_time"
ms-duplex="startTime" data-error="请填写比赛开始时间" required> ms-duplex="startTime" data-error="请填写比赛开始时间" required>
<div class="help-block with-errors"></div> <div class="help-block with-errors"></div>
</div> </div>
</div> </div>
@@ -35,61 +34,66 @@
<div class="form-group"> <div class="form-group">
<input type="text" class="form-control" name="end_time" id="contest_end_time" <input type="text" class="form-control" name="end_time" id="contest_end_time"
ms-duplex="endTime" data-error="请填写比赛结束时间" required> ms-duplex="endTime" data-error="请填写比赛结束时间" required>
<div class="help-block with-errors"></div> <div class="help-block with-errors"></div>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label>允许参加的用户</label>
<div class="form-group"> <div class="form-group">
<select class="form-control" ms-duplex="group" ms-change="addGroup" value="-1"> <label>可见范围</label>
<option value="-1">请选择</option>
<option ms-repeat="groupList" ms-attr-value="$index" ms-visible="!el.chose">{{el.name}}</option> <div>
</select> <span ms-if="showGlobalViewRadio">
<label>
<small><input type="radio" value="true" name="isGlobal" ms-duplex-boolean="isGlobal">全局可见
</small>
</label>
</span>
<span>
<label>
<small><input type="radio" value="false" name="isGlobal" ms-duplex-boolean="isGlobal">小组内可见
</small>
</label>
</span>
</div>
</div> </div>
</div> </div>
<div class="col-md-6" ms-visible="passwordUsable"> <div class="col-md-6" ms-visible="isGlobal">
<label>密码保护</label> <label>密码保护</label>
<div class="form-group"> <div class="form-group">
<input type="text" class="form-control" name="password" placeholder="留空就是公开赛" ms-duplex="password"> <input type="text" class="form-control" name="password" placeholder="留空就是公开赛" ms-duplex="password">
</div> </div>
</div> </div>
<div class="col-md-12"> <div class="form-group col-md-12" ms-visible="!isGlobal">
<div ms-repeat="choseGroupList" class="group-tag" ms-click="removeGroup($index)">{{el.name}}</div> <!-- radio 的value 没有用 但是没有的话,表单验证会出错-->
<div ms-repeat="allGroups" class="col-md-4">
<input type="checkbox" value="group_id" ms-duplex-checked="el.isSelected">&nbsp;&nbsp;{{ el.name }}
</div> </div>
<div class="col-md-6"> </div>
<div class="col-md-3">
<label>排名方式</label> <label>排名方式</label>
</div>
<div class="col-md-3">
<label>结束前是否开放排名</label>
</div>
<div class="col-md-3">
<label>是否公开提交记录</label>
</div>
<div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label><input type="radio" name="mode" ms-duplex-string="mode" value="0"> <label><input type="radio" name="mode" ms-duplex-string="mode" value="0">
<small>ACM</small> <small>ACM</small>
</label> </label>
<label><input type="radio" name="mode" ms-duplex-string="mode" value="1"> <label><input type="radio" name="mode" ms-duplex-string="mode" value="1">
<small>AC数量</small>
</label>
<label><input type="radio" name="mode" ms-duplex-string="mode" value="2">
<small>分数</small> <small>分数</small>
</label> </label>
</div> </div>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<label>公开提交记录</label>
<div class="form-group"> <div class="form-group">
<label class="text"><input type="checkbox" ms-duplex-checked="showRank"> <label class="text"><input type="checkbox" ms-duplex-checked="showSubmission">
<small>放排名</small> <small></small>
</label> </label>
</div> </div>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<label>实时排名</label>
<div class="form-group"> <div class="form-group">
<label class="text"><input type="checkbox" ms-duplex-checked="showSubmission"> <label class="text"><input type="checkbox" ms-duplex-checked="realTimeRank">
<small>允许查看提交记录</small> <small></small>
</label> </label>
</div> </div>
</div> </div>

View File

@@ -24,7 +24,7 @@
<tr ms-repeat="contestList"> <tr ms-repeat="contestList">
<td>{{ el.id }}</td> <td>{{ el.id }}</td>
<td>{{ el.title }}</td> <td>{{ el.title }}</td>
<td ms-text="el.show_rank?'公开':'不公开'"></td> <td ms-text="el.real_time_rank?'实时':'已封榜'"></td>
<td>{{ el.create_time|date("yyyy-MM-dd HH:mm:ss")}}</td> <td>{{ el.create_time|date("yyyy-MM-dd HH:mm:ss")}}</td>
<td>{{ el.created_by.username }}</td> <td>{{ el.created_by.username }}</td>
<td ms-text="el.visible?'可见':'不可见'"></td> <td ms-text="el.visible?'可见':'不可见'"></td>
@@ -87,32 +87,33 @@
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label>允许参加的用户</label>
<div class="form-group"> <div class="form-group">
<select class="form-control" ms-duplex="group" ms-change="addGroup" value="-1"> <label>可见范围</label>
<option value="-1">请选择</option> <span ms-if="showGlobalViewRadio">
<option ms-repeat="groupList" ms-attr-value="$index" ms-visible="!el.chose">{{el.name}}</option> <label>
</select> <small><input type="radio" value="true" name="isGlobal" ms-duplex-boolean="isGlobal">全局可见
</small>
</label>
</span>
<span>
<label>
<small><input type="radio" value="false" name="isGlobal" ms-duplex-boolean="isGlobal">小组内可见
</small>
</label>
</span>
</div> </div>
</div> </div>
<div class="col-md-6" ms-visible="passwordUsable"> <div class="col-md-6" ms-visible="isGlobal">
<label>密码保护</label> <label>密码保护</label>
<input type="text" class="form-control" name="password" placeholder="留空就是公开赛" ms-duplex="editPassword"> <input type="text" class="form-control" name="password" placeholder="留空就是公开赛" ms-duplex="editPassword">
</div> </div>
<div class="col-md-12"> <div class="form-group col-md-12" ms-visible="!isGlobal">
<div ms-repeat="choseGroupList" class="group-tag" ms-click="removeGroup($index)">{{el.name}}</div> <!-- radio 的value 没有用 但是没有的话,表单验证会出错-->
<div ms-repeat="allGroups" class="col-md-4">
<input type="checkbox" value="group_id" ms-duplex-checked="el.isSelected">&nbsp;&nbsp;{{ el.name }}
</div> </div>
<div class="col-md-6">
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
</div>
<div class="col-md-3">
</div>
<div class="col-md-4">
<label>排名方式</label> <label>排名方式</label>
<div class="form-group"> <div class="form-group">
@@ -120,34 +121,31 @@
<small>ACM</small> <small>ACM</small>
</label> </label>
<label><input type="radio" name="mode" ms-duplex-string="editMode" value="1"> <label><input type="radio" name="mode" ms-duplex-string="editMode" value="1">
<small>AC数量</small>
</label>
<label><input type="radio" name="mode" ms-duplex-string="editMode" value="2">
<small>分数</small> <small>分数</small>
</label> </label>
</div> </div>
</div> </div>
<div class="col-md-2"> <div class="col-md-2">
<label>是否可见</label><br> <div class="form-group">
<label>是否可见</label>
<label><input type="checkbox" ms-duplex-checked="editVisible"> <label><input type="checkbox" ms-duplex-checked="editVisible">
<small> 可见</small> <small> 可见</small>
</label> </label>
</div> </div>
</div>
<div class="col-md-3"> <div class="col-md-3">
<label>结束前是否开放排名</label> <label>公开提交记录</label>
<div class="form-group"> <div class="form-group">
<label class="text"><input type="checkbox" ms-duplex-checked="editShowRank"> <label class="text"><input type="checkbox" ms-duplex-checked="editShowSubmission">
<small>放排名</small> <small></small>
</label> </label>
</div> </div>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<label>是否公开提交记录</label> <label>实时排名</label>
<div class="form-group"> <div class="form-group">
<label class="text"><input type="checkbox" ms-duplex-checked="editShowSubmission"> <label class="text"><input type="checkbox" ms-duplex-checked="editRealTimeRank">
<small>允许查看提交记录</small> <small></small>
</label> </label>
</div> </div>
</div> </div>

View File

@@ -48,12 +48,13 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{% if request.user.is_authenticated %}
<div class="form-group"> <div class="form-group">
<label>仅显示当前可参加的比赛 <label>仅显示当前可参加的比赛
<input id="join" type="checkbox" {% if join %}checked{% endif %} onchange="if(this.checked){location.href='/contests/?join=True'}else{location.href='/contests/'}"> <input id="join" type="checkbox" {% if join %}checked{% endif %} onchange="if(this.checked){location.href='/contests/?join=True'}else{location.href='/contests/'}">
</label> </label>
</div> </div>
{% endif %}
<nav> <nav>
<ul class="pager"> <ul class="pager">
{% if previous_page %} {% if previous_page %}

View File

@@ -20,7 +20,7 @@
<div class="problem-section"> <div class="problem-section">
<label class="problem-label">描述</label> <label class="problem-label">描述</label>
<p class="problem-detail">{{ contest_problem.description|safe }}</p> <div class="problem-detail">{{ contest_problem.description|safe }}</div>
</div> </div>
<div class="problem-section"> <div class="problem-section">
<label class="problem-label">输入</label> <label class="problem-label">输入</label>
@@ -60,7 +60,7 @@
<div class="problem-section hide"> <div class="problem-section hide">
<label class="problem-label">提示</label> <label class="problem-label">提示</label>
<p class="problem-detail">{{ contest_problem.hint|safe }}</p> <div class="problem-detail">{{ contest_problem.hint|safe }}</div>
</div> </div>
{% endif %} {% endif %}

View File

@@ -21,7 +21,6 @@
</li> </li>
</ul> </ul>
</div> </div>
{% if submissions %}
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>
<tr class="" success> <tr class="" success>
@@ -64,6 +63,7 @@
</th> </th>
</tr> </tr>
</thead> </thead>
{% if submissions %}
<tbody> <tbody>
{% for item in submissions %} {% for item in submissions %}
<tr> <tr>
@@ -94,10 +94,11 @@
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table>
{% else %} {% else %}
<p>还没有提交记录!</p> <p>本场比赛还没有提交记录</p>
{% endif %} {% endif %}
</table>
<nav> <nav>
<ul class="pager"> <ul class="pager">
{% if previous_page %} {% if previous_page %}

View File

@@ -0,0 +1,114 @@
{% extends 'oj_base.html' %}
{% block body %}
{% load submission %}
{% load user %}
<div class="container main">
<div class="contest-tab">
<ul class="nav nav-tabs nav-tabs-google">
<li role="presentation">
<a href="/contest/{{ contest.id }}/">比赛详情</a>
</li>
<li role="presentation">
<a href="/contest/{{ contest.id }}/problems/">题目</a>
</li>
<li role="presentation" class="active">
<a href="/contest/{{ contest.id }}/submissions/">提交</a>
</li>
<li role="presentation">
<a href="/contest/{{ contest.id }}/rank/">排名</a>
</li>
</ul>
</div>
<table class="table table-bordered">
<thead>
<tr class="" success>
<th>#</th>
<th>题目名称</th>
<th>用户</th>
<th>提交时间</th>
<th>
<div class="dropdown">
<a href="#" class="dropdown-toggle" id="languageFilter" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="true">
语言<span class="caret"></span>
</a>
<ul class="dropdown-menu" aria-labelledby="languageFilter">
<li><a href="/contest/{{ contest.id }}/submissions/?language=1">C</a></li>
<li><a href="/contest/{{ contest.id }}/submissions/?language=2">C++</a></li>
<li><a href="/contest/{{ contest.id }}/submissions/?language=3">Java</a></li>
<li><a href="/contest/{{ contest.id }}/submissions/">取消筛选</a></li>
</ul>
</div>
</th>
<th>运行时间</th>
<th>
<div class="dropdown">
<a href="#" class="dropdown-toggle" id="resultFilter" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="true">
结果<span class="caret"></span>
</a>
<ul class="dropdown-menu" aria-labelledby="resultFilter">
<li><a href="/contest/{{ contest.id }}/submissions/?result=0">Accepted</a></li>
<li><a href="/contest/{{ contest.id }}/submissions/?result=6">Wrong Answer</a></li>
<li><a href="/contest/{{ contest.id }}/submissions/?result=1">Runtime Error</a></li>
<li><a href="/contest/{{ contest.id }}/submissions/?result=2">Time Limit Exceeded</a></li>
<li><a href="/contest/{{ contest.id }}/submissions/?result=3">Memory Limit Exceeded</a></li>
<li><a href="/contest/{{ contest.id }}/submissions/?result=4">Compile Error</a></li>
<li><a href="/contest/{{ contest.id }}/submissions/?result=5">Format Error</a></li>
<li><a href="/contest/{{ contest.id }}/submissions/">取消筛选</a></li>
</ul>
</div>
</th>
</tr>
</thead>
{% if submissions %}
<tbody>
{% for item in submissions %}
<tr>
<th scope="row"><a href="/submission/{{ item.id }}/">
{{ forloop.counter |add:start_id }}</a></th>
<th scope="row">
<a href="/contest/{{ item.contest_id }}/problem/{{ item.problem_id }}/">{{ item.title }}</a>
</th>
<td>{{ item.user_id|get_username }}</td>
<td>{{ item.create_time }}</td>
<td>
{{ item.language|translate_language }}
</td>
<td>
{% if item.accepted_answer_time %}
{{ item.accepted_answer_time }}ms
{% else %}
--
{% endif %}
</td>
<td class="alert-{{ item.result|translate_result_class }}">
<strong>{{ item.result|translate_result }}</strong>
</td>
</tr>
{% endfor %}
</tbody>
{% else %}
<p>本场比赛还没有提交记录</p>
{% endif %}
</table>
<nav>
<ul class="pager">
{% if previous_page %}
<li class="previous"><a
href="/contest/{{ contest.id }}/submissions/{{ previous_page }}/{% if filter %}?{{ filter.name }}={{ filter.content }}{% endif %}">
<span aria-hidden="true">&larr;</span> 上一页</a></li>
{% endif %}
{% if next_page %}
<li class="next">
<a href="/contest/{{ contest.id }}/submissions/{{ next_page }}/{% if filter %}?{{ filter.name }}={{ filter.content }}{% endif %}">
下一页 <span aria-hidden="true">&rarr;</span></a></li>
{% endif %}
</ul>
</nav>
</div>
{% endblock %}

View File

@@ -16,7 +16,7 @@
<div class="problem-section"> <div class="problem-section">
<label class="problem-label">描述</label> <label class="problem-label">描述</label>
<p class="problem-detail">{{ problem.description|safe }}</p> <div class="problem-detail">{{ problem.description|safe }}</div>
</div> </div>
<div class="problem-section"> <div class="problem-section">
<label class="problem-label">输入</label> <label class="problem-label">输入</label>
@@ -48,7 +48,7 @@
{% if problem.hint %} {% if problem.hint %}
<div class="problem-section hide"> <div class="problem-section hide">
<label class="problem-label">提示</label> <label class="problem-label">提示</label>
<p class="problem-detail">{{ problem.hint|safe }}</p> <div class="problem-detail">{{ problem.hint|safe }}</div>
</div> </div>
{% endif %} {% endif %}
<div class="problem-section hide"> <div class="problem-section hide">

33
utils/views.py Normal file
View File

@@ -0,0 +1,33 @@
# coding=utf-8
from rest_framework.views import APIView
from rest_framework.response import Response
from django.conf import settings
from utils.shortcuts import rand_str
class SimditorImageUploadAPIView(APIView):
def post(self, request):
if "image" not in request.FILES:
return Response(data={
"success": False,
"msg": "上传失败",
"file_path": "/"})
img = request.FILES["image"]
image_name = rand_str() + '.' + str(request.FILES["image"].name.split('.')[-1])
image_dir = settings.IMAGE_UPLOAD_DIR + image_name
try:
with open(image_dir, "wb") as imageFile:
for chunk in img:
imageFile.write(chunk)
except IOError:
return Response(data={
"success": True,
"msg": "上传错误",
"file_path": "/static/upload_image/" + image_name})
return Response(data={
"success": True,
"msg": "",
"file_path": "/static/upload_image/" + image_name})