Add basic implementation for creating new problems

This commit is contained in:
James Wang 2016-04-07 16:36:30 -04:00
parent bb4d106130
commit c8efdd3df4
No known key found for this signature in database
GPG key ID: 5B80C0B3F263CD5B
6 changed files with 59 additions and 12 deletions

0
deploy Normal file → Executable file
View file

View file

@ -132,9 +132,10 @@ class Teams(db.Model):
return False
class Problems(db.Model):
pid = db.Column(db.String(128), primary_key=True, autoincrement=False)
pid = db.Column(db.String(32), primary_key=True, autoincrement=False)
title = db.Column(db.String(128))
category = db.Column(db.String(128))
flag = db.Column(db.String(128))
description = db.Column(db.Text)
value = db.Column(db.Integer)
hint = db.Column(db.Text)
@ -143,11 +144,12 @@ class Problems(db.Model):
threshold = db.Column(db.Integer)
weightmap = db.Column(db.PickleType)
def __init__(self, pid, title, category, description, value, hint="", autogen=False, bonus=0, threshold=0, weightmap={}):
def __init__(self, pid, title, category, description, flag, value, hint="", autogen=False, bonus=0, threshold=0, weightmap={}):
self.pid = pid
self.title = title
self.category = category
self.description = description
self.flag = flag
self.value = value
self.hint = hint
self.autogen = autogen

View file

@ -1,6 +1,7 @@
import hashlib
import logger
import os
import utils
from flask import Blueprint, jsonify, session, request
from flask import current_app as app
@ -18,14 +19,18 @@ def problem_add():
name = request.form["name"]
category = request.form["category"]
description = request.form["description"]
hint = request.form["problem-hint"]
hint = request.form["hint"]
flag = request.form["flag"]
value = request.form["value"]
pid = utils.generate_string()
while Problems.query.filter_by(pid=pid).first():
pid = utils.generate_string()
name_exists = Problems.query.filter_by(name=name).first()
name_exists = Problems.query.filter_by(title=name).first()
if name_exists:
raise WebException("Problem name already taken.")
problem = Problems(name, category, description, hint, flag, value)
problem = Problems(pid, name, category, description, flag, value, hint=hint)
db.session.add(problem)
db.session.commit()

View file

@ -3,3 +3,25 @@ $(document).ready(function() {
e.preventDefault();
});
});
var create_problem = function() {
var input = "#new_problem_form input";
var data = $("#new_problem_form").serializeObject();
$(input).attr("disabled", "disabled");
api_call("POST", "/api/problem/add", data, function(result) {
if (result["success"] == 1) {
display_message("add-status", "success", result["message"], function() {
$(input).removeAttr("disabled");
});
} else {
display_message("add-status", "danger", result["message"], function() {
$(input).removeAttr("disabled");
});
}
}, function(jqXHR, status, error) {
var result = jqXHR["responseText"];
display_message("add-status", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
$(input).removeAttr("disabled");
});
});
}

View file

@ -25,6 +25,24 @@
<h4 class="panel-title">New Problem</h4>
</div>
<div class="panel-body">
<div id="add-status"></div>
<form class="form-horizontal" onsubmit="create_problem(); return false;" id="new_problem_form">
<input class="form-control" name="name" placeholder="Name" required/>
<br>
<textarea class="form-control" name="description" placeholder="Description" required autocomplete="off"/>
<br>
<input class="form-control" name="category" placeholder="Category" required autocomplete="off"/>
<br>
<input class="form-control" name="hint" placeholder="Hint" required/>
<br>
<input class="form-control" name="value" type="number" placeholder="Problem Value" required autocomplete="off"/>
<br>
<input class="form-control" name="flag" placeholder="Flag" required/>
<br>
<div id="new_grader"></div>
<br>
<input type="submit" id="create-problem" class="btn btn-success" value="Create"/>
</form>
</div>
</div>
</div>
@ -43,7 +61,7 @@
<script type="text/javascript">
$(document).ready(function() {
/*$(".selectpicker").selectpicker();
$(".selectpicker").selectpicker();
var config = {
toolbar: [
{ name: "basicstyles", items: [ "Bold", "Italic", "Underline" ] },
@ -54,7 +72,7 @@
]
};
var editor = new EpicEditor({
container: "description",
container: "new_grader",
theme: {
base: "https://cdnjs.cloudflare.com/ajax/libs/epiceditor/0.2.2/themes/base/epiceditor.css",
preview: "https://cdnjs.cloudflare.com/ajax/libs/epiceditor/0.2.2/themes/preview/github.css",
@ -66,6 +84,6 @@
}).load();
var new_grader = ace.edit("new_grader");
new_grader.setTheme("ace/theme/tomorrow");
new_grader.getSession().setMode("ace/mode/python");*/
new_grader.getSession().setMode("ace/mode/python");
});
</script>