diff --git a/deploy b/deploy old mode 100644 new mode 100755 diff --git a/server/api/models.py b/server/api/models.py index 3270b09..0a5b34d 100644 --- a/server/api/models.py +++ b/server/api/models.py @@ -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 diff --git a/server/api/problem.py b/server/api/problem.py index 8e410a4..338fb7c 100644 --- a/server/api/problem.py +++ b/server/api/problem.py @@ -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() @@ -160,4 +165,4 @@ def get_problem(title=None, pid=None): match.update({ "pid": pid }) with app.app_context(): result = Problems.query.filter_by(**match) - return result \ No newline at end of file + return result diff --git a/server/api/utils.py b/server/api/utils.py index c2adef0..3c64f0f 100644 --- a/server/api/utils.py +++ b/server/api/utils.py @@ -99,4 +99,4 @@ def generate_identicon(email, filename): draw.rectangle([(4*cell + margin, (i-10)*cell + margin), (5*cell + margin, (i-9)*cell + margin)], fill=c) image.save(open("pfp/%s.png" % filename, "w"), "PNG") - return \ No newline at end of file + return diff --git a/web/js/admin.js b/web/js/admin.js index c6b7fd6..5874aa1 100644 --- a/web/js/admin.js +++ b/web/js/admin.js @@ -2,4 +2,26 @@ $(document).ready(function() { $(".panel-title > a[data-toggle=collapse]").click(function(e) { e.preventDefault(); }); -}); \ No newline at end of file +}); + +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"); + }); + }); +} diff --git a/web/pages/admin/problems.html b/web/pages/admin/problems.html index 03712a5..992d77c 100644 --- a/web/pages/admin/problems.html +++ b/web/pages/admin/problems.html @@ -25,6 +25,24 @@

New Problem

+
+
+ +
+