From 6aa0a119ffc45f18a440fcbb011af8a09adce118 Mon Sep 17 00:00:00 2001 From: James Wang Date: Thu, 7 Apr 2016 20:58:56 -0400 Subject: [PATCH] Refactor name to title --- server/api/admin.py | 2 +- server/api/models.py | 6 +++--- server/api/problem.py | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/server/api/admin.py b/server/api/admin.py index 6c172a7..68b65b7 100644 --- a/server/api/admin.py +++ b/server/api/admin.py @@ -16,7 +16,7 @@ def problem_data(): for problem in problems: problems_return.append({ "pid": problem.pid, - "name": problem.name, + "title": problem.title, "category": problem.category, "description": problem.description, "hint": problem.hint, diff --git a/server/api/models.py b/server/api/models.py index 98abf5e..0a5b34d 100644 --- a/server/api/models.py +++ b/server/api/models.py @@ -133,7 +133,7 @@ class Teams(db.Model): class Problems(db.Model): pid = db.Column(db.String(32), primary_key=True, autoincrement=False) - name = db.Column(db.String(128)) + title = db.Column(db.String(128)) category = db.Column(db.String(128)) flag = db.Column(db.String(128)) description = db.Column(db.Text) @@ -144,9 +144,9 @@ class Problems(db.Model): threshold = db.Column(db.Integer) weightmap = db.Column(db.PickleType) - def __init__(self, pid, name, category, description, flag, 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.name = name + self.title = title self.category = category self.description = description self.flag = flag diff --git a/server/api/problem.py b/server/api/problem.py index d45c8fe..7f782e3 100644 --- a/server/api/problem.py +++ b/server/api/problem.py @@ -16,7 +16,7 @@ blueprint = Blueprint("problem", __name__) @admins_only @api_wrapper def problem_add(): - name = request.form["name"] + title = request.form["title"] category = request.form["category"] description = request.form["description"] hint = request.form["hint"] @@ -26,11 +26,11 @@ def problem_add(): while Problems.query.filter_by(pid=pid).first(): pid = utils.generate_string() - name_exists = Problems.query.filter_by(name=name).first() - if name_exists: + title_exist = Problems.query.filter_by(title=title).first() + if title_exist: raise WebException("Problem name already taken.") - problem = Problems(pid, name, category, description, flag, value, hint=hint) + problem = Problems(pid, title, category, description, flag, value, hint=hint) db.session.add(problem) db.session.commit() @@ -69,7 +69,7 @@ def problem_delete(): @api_wrapper def problem_update(): pid = request.form["pid"] - name = request.form["name"] + title = request.form["title"] category = request.form["category"] description = request.form["description"] hint = request.form["hint"] @@ -78,7 +78,7 @@ def problem_update(): problem = Problems.query.filter_by(pid=pid).first() if problem: - problem.name = name + problem.title = title problem.category = category problem.description = description problem.hint = hint @@ -111,11 +111,11 @@ def problem_submit(): db.session.add(problem) db.session.commit() - logger.log(__name__, logger.WARNING, "%s has solved %s by submitting %s" % (team.name, problem.name, flag)) + logger.log(__name__, logger.WARNING, "%s has solved %s by submitting %s" % (team.name, problem.title, flag)) return { "success": 1, "message": "Correct!" } else: - logger.log(__name__, logger.WARNING, "%s has incorrectly submitted %s to %s" % (team.name, flag, problem.name)) + logger.log(__name__, logger.WARNING, "%s has incorrectly submitted %s to %s" % (team.name, flag, problem.title)) raise WebException("Incorrect.") else: @@ -130,7 +130,7 @@ def problem_data(): for problem in problems: problem_files = [ str(_file.location) for _file in Files.query.filter_by(pid=int(problem.pid)).all() ] - jason.append({"pid": problem[1], "name": problem[2] ,"category": problem[3], "description": problem[4], "hint": problem[5], "value": problem[6], "solves": problem[7], "files": problem_files}) + jason.append({"pid": problem[1], "title": problem[2] ,"category": problem[3], "description": problem[4], "hint": problem[5], "value": problem[6], "solves": problem[7], "files": problem_files}) return jsonify(data=jason) @@ -144,7 +144,7 @@ def insert_problem(data, force=False): else: raise InternalException("Problem already exists.") - insert = Problems(data["pid"], data["name"], data["category"], data["description"], data["value"]) + insert = Problems(data["pid"], data["title"], data["category"], data["description"], data["value"]) if "hint" in data: insert.hint = data["hint"] if "autogen" in data: insert.autogen = data["autogen"] if "bonus" in data: insert.bonus = data["bonus"] @@ -155,10 +155,10 @@ def insert_problem(data, force=False): return True -def get_problem(name=None, pid=None): +def get_problem(title=None, pid=None): match = {} - if name != None: - match.update({ "name": name }) + if title != None: + match.update({ "title": title }) elif pid != None: match.update({ "pid": pid }) with app.app_context():