Merge branch 'dev' into virusdefender-dev

* dev:
  增加了比赛列表页
  [后端]去掉了用于生产序号的javascript,改为使用模板过滤器实现(我的所有提交)
  [前端]修改完善了添加比赛页面,  比赛列表功能仍不全面,稍后改进[CI SKIP]
  修改了css引用方式[CI SKIP]
  [后端]修改了contest中 api-docs 的小bug[CI SKIP]
  创建前台比赛列表
  去掉冗余语句,因为page变量已经有默认值了,不能为空
  [后端]前台我的提交页面 增强提交序号的显示,原来是显示真实id即随机的散列值,不好看,现在改成自然数序列,但需要结合javascript生成,且是相对值,因为数据库里没有这个字段,有点别扭了.   第二,添加了用户没有提交记录的反馈.   第三,本打算增加筛选功能,但因为URL难以统一作罢,只有在增加新的url才能较好的处理,下次再说拜
  [前端]比赛列表页面(后台)的进一步完善,不包含api
  [后端]修改了我的提交列表的模板样式,整理格式
  [后端]修改我的提交页面,去掉了冗余语句,并添加测试
  [后端-前台]添加了submissions分页显示(只显示当前用户的提交),调用已有的view完成单个submission的显示.显示界面与问题分页显示统一.问题是id的显示.url:http://127.0.0.1:8000/my_submissions/
  [前端]修改添加比赛页面,新增了使用小组api查询该用户所创建的所有的小组的功能[CI SKIP]
  [ÂâçÁ´Ø]Ê∑ªÂä†ÊØî˵õȰµÈù¢Ëøõ‰∏ÄÊ≠•ÂÆåÂñÑ,Ê∑ªÂä†Â≠óÊÆµÂåÖÊã¨ÊòØÂê¶ÊòæÁ§∫Êèê‰∫§,ÊØî˵õÊ®°Âºè,ÈóÆÈ¢òÂàÜÂĺ,ÂÖÅËÆ∏ÂèÇÂä†ÊØî˵õÁöÑÁî®Êà∑ÁªÑ,Âπ∂ÂÆåÂñÑÂÜÖÈÉ®ÈÄªËæë,Âü∫Êú¨ÂèØÁ∫Ü,Âè™ÊòØÊ≤°ÂÜôajaxÊèê‰∫§Êï∞ÊçÆ,ÂíåÂïÊãâÂÂèñÂ∞èÁªÑ‰ø°ÊÅØÁöÑÈÉ®ÂàÜ[CI SKIP]
  [前端]修改了添加比赛页的形式结构,仍有bug[CI SKIP]
  Ê∑[ÂâçÁ´Ø]Ê∑ªÂä†ÊØîËÂêéÂè∞ÊØî˵õÂàó˰®[CI SKIP]
  [ÂâçÁ´Ø]Áªü‰∏ÄÈóÆÈ¢òÈá,ÊØî˵õÂàó˰®jsÁöÑÊñቪ∂Âêç_list.js.  Ê∑ªÂ䆉∫ÜÊØî˵õÂàó˰®ÂíåÁºñËæëÊØî˵õÁöÑȰµÈù¢(§߉Ωì§ʆ∑ºè)[CI SKIP]

Conflicts:
	contest/views.py
This commit is contained in:
virusdefender
2015-08-22 20:49:42 +08:00
16 changed files with 964 additions and 336 deletions

View File

@@ -0,0 +1,231 @@
require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "datetimePicker",
"validator"],
function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) {
avalon.vmodels.add_contest = null;
$("#add-contest-form").validator().on('submit', function (e) {
if (!e.isDefaultPrevented()){
e.preventDefault();
var ajaxData = {
title: vm.title,
description: vm.description,
mode: vm.mode,
contest_type: 0,
show_rank: vm.showRank,
show_user_submission: vm.showSubmission,
//password: vm.password,
start_time: vm.startTime,
end_time: vm.endTime,
visible: true
};
if (vm.choseGroupList[0].id == 0) //everyone | public contest
if (vm.password == "")
ajaxData.contest_type = 1;
else{
ajaxData.password = vm.password;
}
else { // Add groups info
ajaxData.groups = [];
for (var i = 0; vm.choseGroupList[i]; i++)
ajaxData.groups.push(parseInt(vm.choseGroupList[i].id))
}
console.log(ajaxData);
$.ajax({
beforeSend: csrfTokenHeader,
url: "/api/admin/contest/",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(ajaxData),
method: "post",
contentType: "application/json",
success: function (data) {
if (!data.code) {
bsAlert("添加成功!");
console.log(data);
}
else {
bsAlert(data.data);
console.log(data);
}
}
});
console.log(JSON.stringify(ajaxData));
}
return false;
});
editor("#editor");
editor("#problemDescriptionEditor");
editor("#problemHintEditor");
var vm = avalon.define({
$id: "add_contest",
title: "",
description: "",
startTime: "",
endTime: "",
password: "",
mode: "",
showRank: false,
showSubmission: false,
problems: [],
editingProblemId: 0,
editSamples: [],
editTestCaseList: [],
group: "-1",
groupList: [],
choseGroupList: [],
showProblemEditArea: function (problemIndex) {
if (vm.editingProblemId == problemIndex){
vm.problems[vm.editingProblemId-1].samples = vm.editSamples;
vm.editingProblemId = 0;
}
else {
if (vm.editingProblemId)
{
vm.problems[vm.editingProblemId-1].samples = vm.editSamples;
vm.problems[vm.editingProblemId-1].testCaseList = vm.editTestCaseList;
}
vm.editingProblemId = problemIndex;
vm.editSamples = [];
vm.editSamples = vm.problems[vm.editingProblemId-1].samples;
vm.editTestCaseList = [];
vm.editTestCaseList = vm.problems[vm.editingProblemId-1].testCaseList;
}
},
passwordUsable: false,
add_problem: function () {
var problem = {
title: "",
timeLimit: 1000,
memoryLimit: 256,
description: "",
samples: [],
visible: true,
test_case_id: "",
testCaseList: [],
hint: "",
score: 0,
uploadSuccess: false,
};
vm.problems.push(problem);
vm.showProblemEditArea(vm.problems.length);
},
del_problem: function (problemIndex) {
if (confirm("你确定要删除么?")) {
vm.editingProblemId = 0;
vm.problems.remove(vm.problems[problemIndex-1]);
}
},
hidden: function () {
vm.problems[vm.editingProblemId-1].samples = editSamples;
vm.problems[vm.editingProblemId-1].testCaseList = editTestCaseList;
vm.editingProblemId = 0;
},
toggle: function (item) {
item.visible = !item.visible;
},
add_sample: function () {
vm.editSamples.push({visible: true, input: "", output: ""});
},
del_sample: function (sample) {
if (confirm("你确定要删除么?")) {
editSamples.remove(sample);
}
},
getBtnContent: function (item) {
if (item.visible)
return "折叠";
return "展开";
},
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});
},
unchose: 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]);
}
});
var isSuperAdmin = true;
$.ajax({ //用于获取该用户创建的所有小组的ajax请求
beforeSend: csrfTokenHeader,
url: "/api/admin/group/?my_group=true",
dataType: "json",
method: "get",
contentType: "application/json",
success: function (data) {
if (!data.code) {
if (isSuperAdmin)
vm.groupList.push({id:0, name:"所有人", chose: false});
for (var key in data.data) {
data.data[key].chose = false;
vm.groupList.push(data.data[key]);
}
}
else {
bsAlert(data.data);
console.log(data);
}
}
});
uploader("#uploader", "/api/admin/test_case_upload/", function (file, respond) {
if (respond.code)
bsAlert(respond.data);
else {
vm.problems[vm.editingProblemId-1].test_case_id = respond.data.test_case_id;
vm.problems[vm.editingProblemId-1].uploadSuccess = true;
vm.editTestCaseList = [];
for (var i = 0; i < respond.data.file_list.input.length; i++) {
vm.editTestCaseList.push({
input: respond.data.file_list.input[i],
output: respond.data.file_list.output[i]
});
}
vm.problems[vm.editingProblemId-1].testCaseList = vm.editTestCaseList;
bsAlert("测试数据添加成功!共添加"+vm.editTestCaseList.length +"组测试数据");
}
},
function(){
if (vm.editingProblemId == 0)
{
bsAlert("你还未指定一道题目!");
return false;
}
}
);
avalon.scan();
$("#contest_start_time").datetimepicker({
format: "yyyy-mm-dd hh:ii",
minuteStep: 5,
weekStart: 1,
language: "zh-CN"
});
$("#contest_end_time").datetimepicker({
format: "yyyy-mm-dd hh:ii",
minuteStep: 5,
weekStart: 1,
language: "zh-CN"
});
});

View File

@@ -1,242 +0,0 @@
require(["jquery", "avalon", "editor", "uploader", "bs_alert", "datetimepicker",
"validation",],
function ($, avalon, editor, uploader, bs_alert) {
avalon.vmodels.add_contest = null;
$("#add-contest-form")
.formValidation({
framework: "bootstrap",
fields: {
name: {
validators: {
notEmpty: {
message: "请填写比赛名称"
},
stringLength: {
min: 1,
max: 30,
message: "名称不能超过30个字"
}
}
},
description: {
validators: {
notEmpty: {
message: "请输入描述"
}
}
},
start_time: {
validators: {
notEmpty: {
message: "请填写开始时间"
},
date: {
format: "YYYY-MM-DD h:m",
message: "请输入一个正确的日期格式"
}
}
},
end_time: {
validators: {
notEmpty: {
message: "请填写结束时间"
},
date: {
format: "YYYY-MM-DD h:m",
message: "请输入一个正确的日期格式"
}
}
},
password: {
validators: {
stringLength: {
min: 0,
max: 30,
message: "密码不能超过10个字符"
}
}
},
"problem_name[]": {
validators: {
notEmpty: {
message: "请输入题目名称"
},
stringLength: {
min: 1,
max: 30,
message: "题目不能超过30个字符"
}
}
},
"cpu[]": {
validators: {
notEmpty: {
message: "请输入时间限制"
},
integer: {
message: "时间限制用整数表示"
},
between: {
inclusive: true,
min: 1,
max: 5000,
message: "只能在1-5000之间"
}
}
},
"memory[]": {
validators: {
notEmpty: {
message: "请输入内存"
},
integer: {
message: "请输入一个合法的数字"
}
}
}
}
})
.on("success.form.fv", function (e) {
e.preventDefault();
var data = {
title: vm.title, description: vm.description, start_time: vm.startTime, end_time: vm.endTime,
password: vm.password, model: vm.model, open_rank: vm.openRank, problems: []
};
for (var i = 0; i < vm.problems.length; i++) {
var problem = {
title: vm.problems[i].title, description: vm.problems[i].description,
cpu: vm.problems[i].cpu, memory: vm.problems[i].memory, samples: []
};
for (var j = 0; j < vm.problems[i].samples.length; j++) {
problem.samples.push({
input: vm.problems[i].samples[j].input,
output: vm.problems[i].samples[j].output
})
}
data.problems.push(problem);
}
console.log(data);
});
function make_id() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 5; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
var upLoaderInited = false;
editor("#editor");
var vm = avalon.define({
$id: "add_contest",
title: "",
problemCount: 0,
description: "",
startTime: "",
endTime: "",
password: "",
model: "",
openRank: false,
problems: [],
problemNo: "-1",
add_problem: function () {
var problem_id = make_id();
var problem = {
id: problem_id,
title: "",
cpu: 1000,
memory: 256,
description: "",
samples: [],
visible: true,
test_case_id: "",
testCaseList: [],
hint: "",
difficulty: 0,
uploadSuccess: false
};
vm.problems.push(problem);
var id = vm.problems.length - 1;
editor("#problem-" + problem_id + "-description");
var hinteditor = editor("#problem-" + problem_id +"-hint");
$("#add-contest-form").formValidation('addField', $('[name="problem_name[]"]'));
$("#add-contest-form").formValidation('addField', $('[name="cpu[]"]'));
$("#add-contest-form").formValidation('addField', $('[name="memory[]"]'));
},
del_problem: function (problem) {
if (confirm("你确定要删除么?")) {
vm.problems.remove(problem);
}
},
toggle: function (item) {
item.visible = !item.visible;
},
add_sample: function (problem) {
problem.samples.push({id: make_id(), visible: true, input: "", output: ""});
},
del_sample: function (problem, sample) {
if (confirm("你确定要删除么?")) {
problem.samples.remove(sample);
}
},
getBtnContent: function (item) {
if (item.visible)
return "折叠";
return "展开";
}
});
uploader("#uploader", "/api/admin/test_case_upload/", function (file, respond) {
if (respond.code)
bs_alert(respond.data);
else {
var index = parseInt(vm.problemNo)-1;
vm.problems[index].test_case_id = respond.data.test_case_id;
vm.problems[index].uploadSuccess = true;
vm.problems[index].testCaseList = [];
for (var i = 0; i < respond.data.file_list.input.length; i++) {
vm.problems[index].testCaseList.push({
input: respond.data.file_list.input[i],
output: respond.data.file_list.output[i]
});
}
bs_alert("测试数据添加成功!共添加"+vm.problems[index].testCaseList.length +"组测试数据");
}
},
function(){
console.log(vm.problemNo);
if (vm.problemNo == "-1")
{
bs_alert("你还未指定一道题目!");
return false;
}
}
);
isUploaderInited = true;
avalon.scan();
$("#contest_start_time").datetimepicker({
format: "yyyy-mm-dd hh:ii",
minuteStep: 5,
weekStart: 1,
language: "zh-CN"
});
$("#contest_end_time").datetimepicker({
format: "yyyy-mm-dd hh:ii",
minuteStep: 5,
weekStart: 1,
language: "zh-CN"
});
$("#contest_start_time").datetimepicker()
.on("hide", function (ev) {
$("#add-contest-form")
.formValidation("revalidateField", "start_time");
});
$("#contest_end_time").datetimepicker()
.on("hide", function (ev) {
$("#add-contest-form")
.formValidation("revalidateField", "end_time");
});
});

View File

@@ -0,0 +1,137 @@
require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker"], function ($, avalon, csrfTokenHeader, bsAlert, editor) {
avalon.ready(function () {
if(avalon.vmodels.contestList){
vm = avalon.vmodels.contestList;
vm.editingContest = 0;
}
else {
var vm = avalon.define({
$id: "contestList",
contestList: [],
previousPage: 0,
nextPage: 0,
page: 1,
totalPage: 1,
group: "-1",
groupList: [],
keyword: "",
editingContestId: 0,
editTitle: "",
editProblemList: [],
editPassword: "",
editStartTime: "",
editEndTime: "",
editMode: "",
editShowRank: false,
editShowSubmission: false,
editProblemList: [],
editingProblemId: 0,
editSamples: [],
editTestCaseList: [],
editChoseGroupList: [],
modelNameList: ["ACM", "AC总数", "分数"],
contestTypeNameList: ["小组赛", "公开赛", "有密码保护的公开赛"],
getNext: function () {
if (!vm.nextPage)
return;
getPageData(vm.page + 1);
},
getPrevious: function () {
if (!vm.previousPage)
return;
getPageData(vm.page - 1);
},
getBtnClass: function (btn) {
if (btn == "next") {
return vm.nextPage ? "btn btn-primary" : "btn btn-primary disabled";
}
else {
return vm.previousPage ? "btn btn-primary" : "btn btn-primary disabled";
}
},
getPage: function (page_index) {
getPageData(page_index);
},
showEditContestArea: function (contestId) {
if (contestId == vm.editingContestId)
vm.editingContestId = 0;
else {
vm.editingContestId = contestId;
vm.editTitle = vm.contestList[contestId-1].title;
vm.editEndTime = vm.contestList[contestId-1].end_time;
vm.editPassword = vm.contestList[contestId-1].password;
vm.editStartTime = vm.contestList[contestId-1].start_time;
vm.editMode = vm.contestList[contestId-1].mode;
vm.editChoseGroupList = [];
//= vm.contestList[contestId-1].group;//
/*for (var key in vm.contestList[contestId-1].groups){
var id = parseInt(vm.contestList[contestId-1].groups);
for ()
vm.editChoseGroupList.push({
name:vm.groupList[vm.group].name,
index:index,
id:parseInt(vm.contestList[contestId-1].groups)
});
}*/
vm.editShowRank = vm.contestList[contestId-1].show_rank;
vm.editShowSubmission = vm.contestList[contestId-1].show_user_submission;
//vm.editProblemList = vm.contestList[contestId-1].problems
editor("#editor").setValue(vm.contestList[contestId-1].description);
vm.editingProblemList = vm.contestList[contestId-1].problemList;
}
}
});
getPageData(1);
}
function getPageData(page) {
var url = "/api/admin/contest/?paging=true&page=" + page + "&page_size=10";
if (vm.keyword != "")
url += "&keyword=" + vm.keyword;
$.ajax({
url: url,
dataType: "json",
method: "get",
success: function (data) {
if (!data.code) {
vm.contestList = data.data.results;
vm.totalPage = data.data.total_page;
vm.previousPage = data.data.previous_page;
vm.nextPage = data.data.next_page;
vm.page = page;
}
else {
bsAlert(data.data);
}
}
});
}
var isSuperAdmin = true;
$.ajax({ //用于获取该用户创建的所有小组的ajax请求
beforeSend: csrfTokenHeader,
url: "/api/admin/group/?my_group=true",
dataType: "json",
method: "get",
contentType: "application/json",
success: function (data) {
if (!data.code) {
if (isSuperAdmin)
vm.groupList.push({id:0, name:"所有人", chose: false});
for (var key in data.data) {
data.data[key].chose = false;
vm.groupList.push(data.data[key]);
}
}
else {
bsAlert(data.data);
console.log(data);
}
}
});
});
avalon.scan();
});