def admin_chals(): if request.method == 'POST': chals = Challenges.query.add_columns( 'id', 'type', 'name', 'value', 'description', 'category', 'hidden', 'max_attempts').order_by(Challenges.value).all() json_data = {'game': []} for x in chals: type_class = CHALLENGE_CLASSES.get(x.type) type_name = type_class.name if type_class else None json_data['game'].append({ 'id': x.id, 'name': x.name, 'value': x.value, 'description': x.description, 'category': x.category, 'hidden': x.hidden, 'max_attempts': x.max_attempts, 'type': x.type, 'type_name': type_name, 'type_data': { 'id': type_class.id, 'name': type_class.name, 'templates': type_class.templates, 'scripts': type_class.scripts, } }) db.session.close() return jsonify(json_data) else: challenges = Challenges.query.all() return render_template('admin/challenges.html', challenges=challenges)
def get_chal_class(class_id): """ Utility function used to get the corresponding class from a class ID. :param class_id: String representing the class ID :return: Challenge class """ cls = CHALLENGE_CLASSES.get(class_id) if cls is None: raise KeyError return cls
def get(self): response = {} for class_id in CHALLENGE_CLASSES: challenge_class = CHALLENGE_CLASSES.get(class_id) response[challenge_class.id] = { "id": challenge_class.id, "name": challenge_class.name, "templates": challenge_class.templates, "scripts": challenge_class.scripts, } return {"success": True, "data": response}
def get(self): response = {} for class_id in CHALLENGE_CLASSES: challenge_class = CHALLENGE_CLASSES.get(class_id) response[challenge_class.id] = { 'id': challenge_class.id, 'name': challenge_class.name, 'templates': challenge_class.templates, 'scripts': challenge_class.scripts, } return {'success': True, 'data': response}
def admin_chal_types(): data = {} for class_id in CHALLENGE_CLASSES: challenge_class = CHALLENGE_CLASSES.get(class_id) data[challenge_class.id] = { 'id': challenge_class.id, 'name': challenge_class.name, 'templates': challenge_class.templates, 'scripts': challenge_class.scripts, } return jsonify(data)
def admin_chals(): if request.method == 'POST': chals = Challenges.query.order_by(Challenges.value).all() json_data = {'game': []} for chal in chals: tags = [ tag.tag for tag in Tags.query.add_columns('tag').filter_by( chal=chal.id).all() ] files = [ str(f.location) for f in Files.query.filter_by(chal=chal.id).all() ] hints = [] for hint in Hints.query.filter_by(chal=chal.id).all(): hints.append({ 'id': hint.id, 'cost': hint.cost, 'hint': hint.hint }) type_class = CHALLENGE_CLASSES.get(chal.type) type_name = type_class.name if type_class else None json_data['game'].append({ 'id': chal.id, 'name': chal.name, 'value': chal.value, 'description': chal.description, 'category': chal.category, 'files': files, 'tags': tags, 'hints': hints, 'hidden': chal.hidden, 'max_attempts': chal.max_attempts, 'type': chal.type, 'type_name': type_name, 'type_data': { 'id': type_class.id, 'name': type_class.name, 'templates': type_class.templates, 'scripts': type_class.scripts, } }) db.session.close() return jsonify(json_data) else: challenges = Challenges.query.all() return render_template('admin/challenges.html', challenges=challenges)
def admin_chals(page): page = abs(int(page)) results_per_page = 10 page_start = results_per_page * (page - 1) page_end = results_per_page * (page - 1) + results_per_page if request.method == 'POST': chals = Challenges.query.order_by(Challenges.id.desc()).slice(page_start, page_end).all() json_data = {'game': []} for chal in chals: tags = [tag.tag for tag in Tags.query.add_columns('tag').filter_by(chal=chal.id).all()] files = [str(f.location) for f in Files.query.filter_by(chal=chal.id).all()] hints = [] for hint in Hints.query.filter_by(chal=chal.id).all(): hints.append({'id': hint.id, 'cost': hint.cost, 'hint': hint.hint}) type_class = CHALLENGE_CLASSES.get(chal.type) type_name = type_class.name if type_class else None json_data['game'].append({ 'id': chal.id, 'name': chal.name, 'value': chal.value, 'description': chal.description, 'category': chal.category, 'files': files, 'tags': tags, 'hints': hints, 'hidden': chal.hidden, 'max_attempts': chal.max_attempts, 'type': chal.type, 'type_name': type_name, 'type_data': { 'id': type_class.id, 'name': type_class.name, 'templates': type_class.templates, 'scripts': type_class.scripts, } }) db.session.close() return jsonify(json_data) else: count = Challenges.query.count() challenges = Challenges.query.order_by(Challenges.id.desc()).slice(page_start, page_end).all() pages = int(count / results_per_page) + (count % results_per_page > 0) return render_template('admin/challenges.html', challenges=challenges, challenge_pages=pages, curr_page=page)
def admin_chals(): if request.method == 'POST': chals = Challenges.query.add_columns( 'id', 'type', 'name', 'value', 'description', 'category', 'hidden', 'max_attempts').order_by(Challenges.value).all() teams_with_points = db.session.query(Solves.teamid).join(Teams).filter( Teams.banned == False).group_by(Solves.teamid).count() json_data = {'game': []} for x in chals: solve_count = Solves.query.join(Teams, Solves.teamid == Teams.id).filter( Solves.chalid == x[1], Teams.banned == False).count() if teams_with_points > 0: percentage = (float(solve_count) / float(teams_with_points)) else: percentage = 0.0 type_class = CHALLENGE_CLASSES.get(x.type) type_name = type_class.name if type_class else None json_data['game'].append({ 'id': x.id, 'name': x.name, 'value': x.value, 'description': x.description, 'category': x.category, 'hidden': x.hidden, 'max_attempts': x.max_attempts, 'type': x.type, 'type_name': type_name, 'percentage_solved': percentage, 'type_data': { 'id': type_class.id, 'name': type_class.name, 'templates': type_class.templates, 'scripts': type_class.scripts, } }) db.session.close() return jsonify(json_data) else: return render_template('admin/chals.html')
def admin_chals(): if request.method == 'POST': chals = Challenges.query.add_columns('id', 'type', 'name', 'value', 'description', 'category', 'hidden', 'max_attempts').order_by(Challenges.value).all() teams_with_points = db.session.query(Solves.teamid).join(Teams).filter( Teams.banned == False).group_by(Solves.teamid).count() json_data = {'game': []} for x in chals: solve_count = Solves.query.join(Teams, Solves.teamid == Teams.id).filter( Solves.chalid == x[1], Teams.banned == False).count() if teams_with_points > 0: percentage = (float(solve_count) / float(teams_with_points)) else: percentage = 0.0 type_class = CHALLENGE_CLASSES.get(x.type) type_name = type_class.name if type_class else None json_data['game'].append({ 'id': x.id, 'name': x.name, 'value': x.value, 'description': x.description, 'category': x.category, 'hidden': x.hidden, 'max_attempts': x.max_attempts, 'type': x.type, 'type_name': type_name, 'percentage_solved': percentage }) db.session.close() return jsonify(json_data) else: return render_template('admin/chals.html')
def admin_chal_types(): data = {} for class_id in CHALLENGE_CLASSES: data[class_id] = CHALLENGE_CLASSES.get(class_id).name return jsonify(data)