Refactor name to title

This commit is contained in:
James Wang 2016-04-07 20:58:56 -04:00
parent 6df67c0e76
commit 6aa0a119ff
No known key found for this signature in database
GPG key ID: 5B80C0B3F263CD5B
3 changed files with 17 additions and 17 deletions

View file

@ -16,7 +16,7 @@ def problem_data():
for problem in problems: for problem in problems:
problems_return.append({ problems_return.append({
"pid": problem.pid, "pid": problem.pid,
"name": problem.name, "title": problem.title,
"category": problem.category, "category": problem.category,
"description": problem.description, "description": problem.description,
"hint": problem.hint, "hint": problem.hint,

View file

@ -133,7 +133,7 @@ class Teams(db.Model):
class Problems(db.Model): class Problems(db.Model):
pid = db.Column(db.String(32), primary_key=True, autoincrement=False) 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)) category = db.Column(db.String(128))
flag = db.Column(db.String(128)) flag = db.Column(db.String(128))
description = db.Column(db.Text) description = db.Column(db.Text)
@ -144,9 +144,9 @@ class Problems(db.Model):
threshold = db.Column(db.Integer) threshold = db.Column(db.Integer)
weightmap = db.Column(db.PickleType) 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.pid = pid
self.name = name self.title = title
self.category = category self.category = category
self.description = description self.description = description
self.flag = flag self.flag = flag

View file

@ -16,7 +16,7 @@ blueprint = Blueprint("problem", __name__)
@admins_only @admins_only
@api_wrapper @api_wrapper
def problem_add(): def problem_add():
name = request.form["name"] title = request.form["title"]
category = request.form["category"] category = request.form["category"]
description = request.form["description"] description = request.form["description"]
hint = request.form["hint"] hint = request.form["hint"]
@ -26,11 +26,11 @@ def problem_add():
while Problems.query.filter_by(pid=pid).first(): while Problems.query.filter_by(pid=pid).first():
pid = utils.generate_string() pid = utils.generate_string()
name_exists = Problems.query.filter_by(name=name).first() title_exist = Problems.query.filter_by(title=title).first()
if name_exists: if title_exist:
raise WebException("Problem name already taken.") 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.add(problem)
db.session.commit() db.session.commit()
@ -69,7 +69,7 @@ def problem_delete():
@api_wrapper @api_wrapper
def problem_update(): def problem_update():
pid = request.form["pid"] pid = request.form["pid"]
name = request.form["name"] title = request.form["title"]
category = request.form["category"] category = request.form["category"]
description = request.form["description"] description = request.form["description"]
hint = request.form["hint"] hint = request.form["hint"]
@ -78,7 +78,7 @@ def problem_update():
problem = Problems.query.filter_by(pid=pid).first() problem = Problems.query.filter_by(pid=pid).first()
if problem: if problem:
problem.name = name problem.title = title
problem.category = category problem.category = category
problem.description = description problem.description = description
problem.hint = hint problem.hint = hint
@ -111,11 +111,11 @@ def problem_submit():
db.session.add(problem) db.session.add(problem)
db.session.commit() 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!" } return { "success": 1, "message": "Correct!" }
else: 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.") raise WebException("Incorrect.")
else: else:
@ -130,7 +130,7 @@ def problem_data():
for problem in problems: for problem in problems:
problem_files = [ str(_file.location) for _file in Files.query.filter_by(pid=int(problem.pid)).all() ] 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) return jsonify(data=jason)
@ -144,7 +144,7 @@ def insert_problem(data, force=False):
else: else:
raise InternalException("Problem already exists.") 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 "hint" in data: insert.hint = data["hint"]
if "autogen" in data: insert.autogen = data["autogen"] if "autogen" in data: insert.autogen = data["autogen"]
if "bonus" in data: insert.bonus = data["bonus"] if "bonus" in data: insert.bonus = data["bonus"]
@ -155,10 +155,10 @@ def insert_problem(data, force=False):
return True return True
def get_problem(name=None, pid=None): def get_problem(title=None, pid=None):
match = {} match = {}
if name != None: if title != None:
match.update({ "name": name }) match.update({ "title": title })
elif pid != None: elif pid != None:
match.update({ "pid": pid }) match.update({ "pid": pid })
with app.app_context(): with app.app_context():