Hide scores (#224)

* Starting work on hide_scores functionality

* Hide teams in more views

* Starting work on hide_scores functionality

* Hide teams in more views
This commit is contained in:
Kevin Chung
2017-03-08 00:21:39 -05:00
committed by GitHub
parent e9df6bf803
commit d0cb92c644
14 changed files with 96 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
from flask import render_template, jsonify, Blueprint, redirect, url_for, request
from sqlalchemy.sql.expression import union_all
from CTFd.utils import unix_time, authed, get_config
from CTFd.utils import unix_time, authed, get_config, hide_scores
from CTFd.models import db, Teams, Solves, Awards, Challenges
scoreboard = Blueprint('scoreboard', __name__)
@@ -37,16 +37,22 @@ def get_standings(admin=False, count=None):
def scoreboard_view():
if get_config('view_scoreboard_if_authed') and not authed():
return redirect(url_for('auth.login', next=request.path))
if hide_scores():
return render_template('scoreboard.html', errors=['Scores are currently hidden'])
standings = get_standings()
return render_template('scoreboard.html', teams=standings)
@scoreboard.route('/scores')
def scores():
json = {'standings': []}
if get_config('view_scoreboard_if_authed') and not authed():
return redirect(url_for('auth.login', next=request.path))
if hide_scores():
return jsonify(json)
standings = get_standings()
json = {'standings': []}
for i, x in enumerate(standings):
json['standings'].append({'pos': i + 1, 'id': x.teamid, 'team': x.name, 'score': int(x.score)})
return jsonify(json)
@@ -54,16 +60,15 @@ def scores():
@scoreboard.route('/top/<int:count>')
def topteams(count):
json = {'scores': {}}
if get_config('view_scoreboard_if_authed') and not authed():
return redirect(url_for('auth.login', next=request.path))
try:
count = int(count)
except ValueError:
count = 10
if hide_scores():
return jsonify(json)
if count > 20 or count < 0:
count = 10
json = {'scores': {}}
standings = get_standings(count=count)
for team in standings: