mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 06:24:23 +01:00
Plugins enhanced utils (#231)
* Updating utils functions to be monkey patchable * Also fixing a team email update issue * Adding more tests
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
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, hide_scores
|
||||
from CTFd.models import db, Teams, Solves, Awards, Challenges
|
||||
|
||||
from CTFd import utils
|
||||
|
||||
scoreboard = Blueprint('scoreboard', __name__)
|
||||
|
||||
|
||||
@@ -35,9 +36,9 @@ def get_standings(admin=False, count=None):
|
||||
|
||||
@scoreboard.route('/scoreboard')
|
||||
def scoreboard_view():
|
||||
if get_config('view_scoreboard_if_authed') and not authed():
|
||||
if utils.get_config('view_scoreboard_if_authed') and not utils.authed():
|
||||
return redirect(url_for('auth.login', next=request.path))
|
||||
if hide_scores():
|
||||
if utils.hide_scores():
|
||||
return render_template('scoreboard.html', errors=['Scores are currently hidden'])
|
||||
standings = get_standings()
|
||||
return render_template('scoreboard.html', teams=standings)
|
||||
@@ -46,9 +47,9 @@ def scoreboard_view():
|
||||
@scoreboard.route('/scores')
|
||||
def scores():
|
||||
json = {'standings': []}
|
||||
if get_config('view_scoreboard_if_authed') and not authed():
|
||||
if utils.get_config('view_scoreboard_if_authed') and not utils.authed():
|
||||
return redirect(url_for('auth.login', next=request.path))
|
||||
if hide_scores():
|
||||
if utils.hide_scores():
|
||||
return jsonify(json)
|
||||
|
||||
standings = get_standings()
|
||||
@@ -61,9 +62,9 @@ def scores():
|
||||
@scoreboard.route('/top/<int:count>')
|
||||
def topteams(count):
|
||||
json = {'scores': {}}
|
||||
if get_config('view_scoreboard_if_authed') and not authed():
|
||||
if utils.get_config('view_scoreboard_if_authed') and not utils.authed():
|
||||
return redirect(url_for('auth.login', next=request.path))
|
||||
if hide_scores():
|
||||
if utils.hide_scores():
|
||||
return jsonify(json)
|
||||
|
||||
if count > 20 or count < 0:
|
||||
@@ -80,14 +81,14 @@ def topteams(count):
|
||||
'chal': x.chalid,
|
||||
'team': x.teamid,
|
||||
'value': x.chal.value,
|
||||
'time': unix_time(x.date)
|
||||
'time': utils.unix_time(x.date)
|
||||
})
|
||||
for award in awards:
|
||||
json['scores'][team.name].append({
|
||||
'chal': None,
|
||||
'team': award.teamid,
|
||||
'value': award.value,
|
||||
'time': unix_time(award.date)
|
||||
'time': utils.unix_time(award.date)
|
||||
})
|
||||
json['scores'][team.name] = sorted(json['scores'][team.name], key=lambda k: k['time'])
|
||||
return jsonify(json)
|
||||
|
||||
Reference in New Issue
Block a user