mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 06:24:23 +01:00
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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user