mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 06:24:23 +01:00
Latest set of changes (#190)
* PEP 8 compliance (#183) * Group imports: standard library, third party, local * Remove unnecessary spaces * Comments should start with a # and a single space * Adding tests for GETs on user facing pages * Adding more user facing tests 51% test coverage * Fixes #182 * Cleaning up Pages Fixes a bug with CSS updating
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
from flask import current_app as app, session, render_template, jsonify, Blueprint, redirect, url_for, request
|
||||
from CTFd.utils import unix_time, authed, get_config
|
||||
from CTFd.models import db, Teams, Solves, Awards, Challenges
|
||||
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.models import db, Teams, Solves, Awards, Challenges
|
||||
|
||||
scoreboard = Blueprint('scoreboard', __name__)
|
||||
|
||||
|
||||
def get_standings(admin=False, count=None):
|
||||
score = db.func.sum(Challenges.value).label('score')
|
||||
date = db.func.max(Solves.date).label('date')
|
||||
@@ -16,13 +18,13 @@ def get_standings(admin=False, count=None):
|
||||
.group_by(results.columns.teamid).subquery()
|
||||
if admin:
|
||||
standings_query = db.session.query(Teams.id.label('teamid'), Teams.name.label('name'), Teams.banned, sumscores.columns.score) \
|
||||
.join(sumscores, Teams.id == sumscores.columns.teamid) \
|
||||
.order_by(sumscores.columns.score.desc(), sumscores.columns.date)
|
||||
.join(sumscores, Teams.id == sumscores.columns.teamid) \
|
||||
.order_by(sumscores.columns.score.desc(), sumscores.columns.date)
|
||||
else:
|
||||
standings_query = db.session.query(Teams.id.label('teamid'), Teams.name.label('name'), sumscores.columns.score) \
|
||||
.join(sumscores, Teams.id == sumscores.columns.teamid) \
|
||||
.filter(Teams.banned == False) \
|
||||
.order_by(sumscores.columns.score.desc(), sumscores.columns.date)
|
||||
.join(sumscores, Teams.id == sumscores.columns.teamid) \
|
||||
.filter(Teams.banned == False) \
|
||||
.order_by(sumscores.columns.score.desc(), sumscores.columns.date)
|
||||
if count is None:
|
||||
standings = standings_query.all()
|
||||
else:
|
||||
@@ -44,9 +46,9 @@ def scores():
|
||||
if get_config('view_scoreboard_if_authed') and not authed():
|
||||
return redirect(url_for('auth.login', next=request.path))
|
||||
standings = get_standings()
|
||||
json = {'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)})
|
||||
json['standings'].append({'pos': i + 1, 'id': x.teamid, 'team': x.name, 'score': int(x.score)})
|
||||
return jsonify(json)
|
||||
|
||||
|
||||
@@ -56,19 +58,18 @@ def topteams(count):
|
||||
return redirect(url_for('auth.login', next=request.path))
|
||||
try:
|
||||
count = int(count)
|
||||
except:
|
||||
except ValueError:
|
||||
count = 10
|
||||
if count > 20 or count < 0:
|
||||
count = 10
|
||||
|
||||
json = {'scores':{}}
|
||||
json = {'scores': {}}
|
||||
standings = get_standings(count=count)
|
||||
|
||||
for team in standings:
|
||||
solves = Solves.query.filter_by(teamid=team.teamid).all()
|
||||
awards = Awards.query.filter_by(teamid=team.teamid).all()
|
||||
json['scores'][team.name] = []
|
||||
scores = []
|
||||
for x in solves:
|
||||
json['scores'][team.name].append({
|
||||
'chal': x.chalid,
|
||||
|
||||
Reference in New Issue
Block a user