mirror of https://github.com/JohnHammond/CTFd.git
Added defaults to Team boolean columns. Switched comparisons of these columns from ==None to ==False
parent
ad39f5a821
commit
2ba89613e0
|
@ -292,12 +292,12 @@ def admin_chals():
|
||||||
chals = Challenges.query.add_columns('id', 'name', 'value', 'description', 'category', 'hidden').order_by(Challenges.value).all()
|
chals = Challenges.query.add_columns('id', 'name', 'value', 'description', 'category', 'hidden').order_by(Challenges.value).all()
|
||||||
|
|
||||||
teams_with_points = db.session.query(Solves.teamid, Teams.name).join(Teams).filter(
|
teams_with_points = db.session.query(Solves.teamid, Teams.name).join(Teams).filter(
|
||||||
Teams.banned == None).group_by(
|
Teams.banned == False).group_by(
|
||||||
Solves.teamid).count()
|
Solves.teamid).count()
|
||||||
|
|
||||||
json_data = {'game':[]}
|
json_data = {'game':[]}
|
||||||
for x in chals:
|
for x in chals:
|
||||||
solve_count = Solves.query.join(Teams, Solves.teamid == Teams.id).filter(Solves.chalid==x[1], Teams.banned==None).count()
|
solve_count = Solves.query.join(Teams, Solves.teamid == Teams.id).filter(Solves.chalid == x[1], Teams.banned == False).count()
|
||||||
if teams_with_points > 0:
|
if teams_with_points > 0:
|
||||||
percentage = (float(solve_count) / float(teams_with_points))
|
percentage = (float(solve_count) / float(teams_with_points))
|
||||||
else:
|
else:
|
||||||
|
@ -506,7 +506,7 @@ def email_user(teamid):
|
||||||
@admins_only
|
@admins_only
|
||||||
def ban(teamid):
|
def ban(teamid):
|
||||||
user = Teams.query.filter_by(id=teamid).first()
|
user = Teams.query.filter_by(id=teamid).first()
|
||||||
user.banned = 1
|
user.banned = True
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(url_for('admin.admin_scoreboard'))
|
return redirect(url_for('admin.admin_scoreboard'))
|
||||||
|
|
||||||
|
@ -515,7 +515,7 @@ def ban(teamid):
|
||||||
@admins_only
|
@admins_only
|
||||||
def unban(teamid):
|
def unban(teamid):
|
||||||
user = Teams.query.filter_by(id=teamid).first()
|
user = Teams.query.filter_by(id=teamid).first()
|
||||||
user.banned = None
|
user.banned = False
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(url_for('admin.admin_scoreboard'))
|
return redirect(url_for('admin.admin_scoreboard'))
|
||||||
|
|
||||||
|
@ -545,7 +545,7 @@ def admin_graph(graph_type):
|
||||||
json_data['categories'].append({'category':category, 'count':count})
|
json_data['categories'].append({'category':category, 'count':count})
|
||||||
return jsonify(json_data)
|
return jsonify(json_data)
|
||||||
elif graph_type == "solves":
|
elif graph_type == "solves":
|
||||||
solves = Solves.query.join(Teams).filter(Teams.banned==None).add_columns(db.func.count(Solves.chalid)).group_by(Solves.chalid).all()
|
solves = Solves.query.join(Teams).filter(Teams.banned == False).add_columns(db.func.count(Solves.chalid)).group_by(Solves.chalid).all()
|
||||||
json_data = {}
|
json_data = {}
|
||||||
for chal, count in solves:
|
for chal, count in solves:
|
||||||
json_data[chal.chal.name] = count
|
json_data[chal.chal.name] = count
|
||||||
|
@ -633,7 +633,7 @@ def delete_award(award_id):
|
||||||
def admin_scores():
|
def admin_scores():
|
||||||
score = db.func.sum(Challenges.value).label('score')
|
score = db.func.sum(Challenges.value).label('score')
|
||||||
quickest = db.func.max(Solves.date).label('quickest')
|
quickest = db.func.max(Solves.date).label('quickest')
|
||||||
teams = db.session.query(Solves.teamid, Teams.name, score).join(Teams).join(Challenges).filter(Teams.banned == None).group_by(Solves.teamid).order_by(score.desc(), quickest)
|
teams = db.session.query(Solves.teamid, Teams.name, score).join(Teams).join(Challenges).filter(Teams.banned == False).group_by(Solves.teamid).order_by(score.desc(), quickest)
|
||||||
db.session.close()
|
db.session.close()
|
||||||
json_data = {'teams':[]}
|
json_data = {'teams':[]}
|
||||||
for i, x in enumerate(teams):
|
for i, x in enumerate(teams):
|
||||||
|
@ -765,8 +765,8 @@ def admin_correct_key(page='1'):
|
||||||
@admins_only
|
@admins_only
|
||||||
def admin_fails(teamid='all'):
|
def admin_fails(teamid='all'):
|
||||||
if teamid == "all":
|
if teamid == "all":
|
||||||
fails = WrongKeys.query.join(Teams, WrongKeys.teamid == Teams.id).filter(Teams.banned==None).count()
|
fails = WrongKeys.query.join(Teams, WrongKeys.teamid == Teams.id).filter(Teams.banned == False).count()
|
||||||
solves = Solves.query.join(Teams, Solves.teamid == Teams.id).filter(Teams.banned==None).count()
|
solves = Solves.query.join(Teams, Solves.teamid == Teams.id).filter(Teams.banned == False).count()
|
||||||
db.session.close()
|
db.session.close()
|
||||||
json_data = {'fails':str(fails), 'solves': str(solves)}
|
json_data = {'fails':str(fails), 'solves': str(solves)}
|
||||||
return jsonify(json_data)
|
return jsonify(json_data)
|
||||||
|
|
|
@ -56,7 +56,7 @@ def chals():
|
||||||
@challenges.route('/chals/solves')
|
@challenges.route('/chals/solves')
|
||||||
def chals_per_solves():
|
def chals_per_solves():
|
||||||
if can_view_challenges():
|
if can_view_challenges():
|
||||||
solves = Solves.query.join(Teams, Solves.teamid == Teams.id).filter(Teams.banned==None).add_columns(db.func.count(Solves.chalid)).group_by(Solves.chalid).all()
|
solves = Solves.query.join(Teams, Solves.teamid == Teams.id).filter(Teams.banned == False).add_columns(db.func.count(Solves.chalid)).group_by(Solves.chalid).all()
|
||||||
json = {}
|
json = {}
|
||||||
for chal, count in solves:
|
for chal, count in solves:
|
||||||
json[chal.chal.name] = count
|
json[chal.chal.name] = count
|
||||||
|
@ -73,7 +73,7 @@ def solves(teamid=None):
|
||||||
if is_admin():
|
if is_admin():
|
||||||
solves = Solves.query.filter_by(teamid=session['id']).all()
|
solves = Solves.query.filter_by(teamid=session['id']).all()
|
||||||
elif authed():
|
elif authed():
|
||||||
solves = Solves.query.join(Teams, Solves.teamid == Teams.id).filter(Solves.teamid==session['id'], Teams.banned==None).all()
|
solves = Solves.query.join(Teams, Solves.teamid == Teams.id).filter(Solves.teamid == session['id'], Teams.banned == False).all()
|
||||||
else:
|
else:
|
||||||
return redirect(url_for('auth.login', next='solves'))
|
return redirect(url_for('auth.login', next='solves'))
|
||||||
else:
|
else:
|
||||||
|
@ -125,7 +125,7 @@ def fails(teamid):
|
||||||
|
|
||||||
@challenges.route('/chal/<chalid>/solves', methods=['GET'])
|
@challenges.route('/chal/<chalid>/solves', methods=['GET'])
|
||||||
def who_solved(chalid):
|
def who_solved(chalid):
|
||||||
solves = Solves.query.join(Teams, Solves.teamid == Teams.id).filter(Solves.chalid==chalid, Teams.banned==None).order_by(Solves.date.asc())
|
solves = Solves.query.join(Teams, Solves.teamid == Teams.id).filter(Solves.chalid == chalid, Teams.banned == False).order_by(Solves.date.asc())
|
||||||
json = {'teams':[]}
|
json = {'teams':[]}
|
||||||
for solve in solves:
|
for solve in solves:
|
||||||
json['teams'].append({'id':solve.team.id, 'name':solve.team.name, 'date':solve.date})
|
json['teams'].append({'id':solve.team.id, 'name':solve.team.name, 'date':solve.date})
|
||||||
|
|
|
@ -140,9 +140,9 @@ class Teams(db.Model):
|
||||||
affiliation = db.Column(db.String(128))
|
affiliation = db.Column(db.String(128))
|
||||||
country = db.Column(db.String(32))
|
country = db.Column(db.String(32))
|
||||||
bracket = db.Column(db.String(32))
|
bracket = db.Column(db.String(32))
|
||||||
banned = db.Column(db.Boolean)
|
banned = db.Column(db.Boolean, default=False)
|
||||||
verified = db.Column(db.Boolean)
|
verified = db.Column(db.Boolean, default=False)
|
||||||
admin = db.Column(db.Boolean)
|
admin = db.Column(db.Boolean, default=False)
|
||||||
|
|
||||||
def __init__(self, name, email, password):
|
def __init__(self, name, email, password):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -154,7 +154,7 @@ class Teams(db.Model):
|
||||||
|
|
||||||
def score(self):
|
def score(self):
|
||||||
score = db.func.sum(Challenges.value).label('score')
|
score = db.func.sum(Challenges.value).label('score')
|
||||||
team = db.session.query(Solves.teamid, score).join(Teams).join(Challenges).filter(Teams.banned == None, Teams.id==self.id).group_by(Solves.teamid).first()
|
team = db.session.query(Solves.teamid, score).join(Teams).join(Challenges).filter(Teams.banned == False, Teams.id==self.id).group_by(Solves.teamid).first()
|
||||||
award_score = db.func.sum(Awards.value).label('award_score')
|
award_score = db.func.sum(Awards.value).label('award_score')
|
||||||
award = db.session.query(award_score).filter_by(teamid=self.id).first()
|
award = db.session.query(award_score).filter_by(teamid=self.id).first()
|
||||||
if team:
|
if team:
|
||||||
|
@ -165,7 +165,7 @@ class Teams(db.Model):
|
||||||
def place(self):
|
def place(self):
|
||||||
score = db.func.sum(Challenges.value).label('score')
|
score = db.func.sum(Challenges.value).label('score')
|
||||||
quickest = db.func.max(Solves.date).label('quickest')
|
quickest = db.func.max(Solves.date).label('quickest')
|
||||||
teams = db.session.query(Solves.teamid).join(Teams).join(Challenges).filter(Teams.banned == None).group_by(Solves.teamid).order_by(score.desc(), quickest).all()
|
teams = db.session.query(Solves.teamid).join(Teams).join(Challenges).filter(Teams.banned == False).group_by(Solves.teamid).order_by(score.desc(), quickest).all()
|
||||||
#http://codegolf.stackexchange.com/a/4712
|
#http://codegolf.stackexchange.com/a/4712
|
||||||
try:
|
try:
|
||||||
i = teams.index((self.id,)) + 1
|
i = teams.index((self.id,)) + 1
|
||||||
|
|
|
@ -14,7 +14,7 @@ def scoreboard_view():
|
||||||
scores = db.session.query(Solves.teamid.label('teamid'), Teams.name.label('name'), score, Solves.date.label('date')) \
|
scores = db.session.query(Solves.teamid.label('teamid'), Teams.name.label('name'), score, Solves.date.label('date')) \
|
||||||
.join(Teams) \
|
.join(Teams) \
|
||||||
.join(Challenges) \
|
.join(Challenges) \
|
||||||
.filter(Teams.banned == None) \
|
.filter(Teams.banned == False) \
|
||||||
.group_by(Solves.teamid)
|
.group_by(Solves.teamid)
|
||||||
|
|
||||||
awards = db.session.query(Teams.id.label('teamid'), Teams.name.label('name'),
|
awards = db.session.query(Teams.id.label('teamid'), Teams.name.label('name'),
|
||||||
|
@ -41,7 +41,7 @@ def scores():
|
||||||
scores = db.session.query(Solves.teamid.label('teamid'), Teams.name.label('name'), score, Solves.date.label('date')) \
|
scores = db.session.query(Solves.teamid.label('teamid'), Teams.name.label('name'), score, Solves.date.label('date')) \
|
||||||
.join(Teams) \
|
.join(Teams) \
|
||||||
.join(Challenges) \
|
.join(Challenges) \
|
||||||
.filter(Teams.banned == None) \
|
.filter(Teams.banned == False) \
|
||||||
.group_by(Solves.teamid)
|
.group_by(Solves.teamid)
|
||||||
|
|
||||||
awards = db.session.query(Teams.id.label('teamid'), Teams.name.label('name'), db.func.sum(Awards.value).label('score'), Awards.date.label('date'))\
|
awards = db.session.query(Teams.id.label('teamid'), Teams.name.label('name'), db.func.sum(Awards.value).label('score'), Awards.date.label('date'))\
|
||||||
|
@ -79,7 +79,7 @@ def topteams(count):
|
||||||
scores = db.session.query(Solves.teamid.label('teamid'), Teams.name.label('name'), score, Solves.date.label('date')) \
|
scores = db.session.query(Solves.teamid.label('teamid'), Teams.name.label('name'), score, Solves.date.label('date')) \
|
||||||
.join(Teams) \
|
.join(Teams) \
|
||||||
.join(Challenges) \
|
.join(Challenges) \
|
||||||
.filter(Teams.banned == None) \
|
.filter(Teams.banned == False) \
|
||||||
.group_by(Solves.teamid)
|
.group_by(Solves.teamid)
|
||||||
|
|
||||||
awards = db.session.query(Teams.id.label('teamid'), Teams.name.label('name'),
|
awards = db.session.query(Teams.id.label('teamid'), Teams.name.label('name'),
|
||||||
|
|
Loading…
Reference in New Issue