easyctf-2017/server/api/admin.py

20 lines
949 B
Python
Raw Normal View History

2016-01-03 03:15:23 +00:00
from flask import Blueprint, jsonify
from decorators import admins_only, api_wrapper, login_required
from models import db, Problems, Files
2015-12-24 03:51:42 +00:00
2015-12-27 00:19:31 +00:00
blueprint = Blueprint("admin", __name__)
2016-01-03 03:15:23 +00:00
@blueprint.route("/problem/data", methods=["POST"])
#@api_wrapper # Disable atm due to json serialization issues: will fix
@admins_only
@login_required
def problem_data():
problems = Problems.query.add_columns("pid", "name", "category", "description", "hint", "value", "solves", "disabled", "flag").order_by(Problems.value).all()
jason = []
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], "disabled": problem[8], "flag": problem[9], "files": problem_files})
return jsonify(data=jason)