Added defaults to Team boolean columns. Switched comparisons of these columns from ==None to ==False

selenium-screenshot-testing
Nick Gregory 2016-05-12 17:23:16 -04:00
parent ad39f5a821
commit 2ba89613e0
4 changed files with 19 additions and 19 deletions

View File

@ -292,12 +292,12 @@ def admin_chals():
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.banned == None).group_by(
Teams.banned == False).group_by(
Solves.teamid).count()
json_data = {'game':[]}
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:
percentage = (float(solve_count) / float(teams_with_points))
else:
@ -506,7 +506,7 @@ def email_user(teamid):
@admins_only
def ban(teamid):
user = Teams.query.filter_by(id=teamid).first()
user.banned = 1
user.banned = True
db.session.commit()
return redirect(url_for('admin.admin_scoreboard'))
@ -515,7 +515,7 @@ def ban(teamid):
@admins_only
def unban(teamid):
user = Teams.query.filter_by(id=teamid).first()
user.banned = None
user.banned = False
db.session.commit()
return redirect(url_for('admin.admin_scoreboard'))
@ -545,7 +545,7 @@ def admin_graph(graph_type):
json_data['categories'].append({'category':category, 'count':count})
return jsonify(json_data)
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 = {}
for chal, count in solves:
json_data[chal.chal.name] = count
@ -633,7 +633,7 @@ def delete_award(award_id):
def admin_scores():
score = db.func.sum(Challenges.value).label('score')
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()
json_data = {'teams':[]}
for i, x in enumerate(teams):
@ -765,8 +765,8 @@ def admin_correct_key(page='1'):
@admins_only
def admin_fails(teamid='all'):
if teamid == "all":
fails = WrongKeys.query.join(Teams, WrongKeys.teamid == Teams.id).filter(Teams.banned==None).count()
solves = Solves.query.join(Teams, Solves.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 == False).count()
db.session.close()
json_data = {'fails':str(fails), 'solves': str(solves)}
return jsonify(json_data)

View File

@ -56,7 +56,7 @@ def chals():
@challenges.route('/chals/solves')
def chals_per_solves():
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 = {}
for chal, count in solves:
json[chal.chal.name] = count
@ -73,7 +73,7 @@ def solves(teamid=None):
if is_admin():
solves = Solves.query.filter_by(teamid=session['id']).all()
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:
return redirect(url_for('auth.login', next='solves'))
else:
@ -125,7 +125,7 @@ def fails(teamid):
@challenges.route('/chal/<chalid>/solves', methods=['GET'])
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':[]}
for solve in solves:
json['teams'].append({'id':solve.team.id, 'name':solve.team.name, 'date':solve.date})

View File

@ -140,9 +140,9 @@ class Teams(db.Model):
affiliation = db.Column(db.String(128))
country = db.Column(db.String(32))
bracket = db.Column(db.String(32))
banned = db.Column(db.Boolean)
verified = db.Column(db.Boolean)
admin = db.Column(db.Boolean)
banned = db.Column(db.Boolean, default=False)
verified = db.Column(db.Boolean, default=False)
admin = db.Column(db.Boolean, default=False)
def __init__(self, name, email, password):
self.name = name
@ -154,7 +154,7 @@ class Teams(db.Model):
def score(self):
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 = db.session.query(award_score).filter_by(teamid=self.id).first()
if team:
@ -165,7 +165,7 @@ class Teams(db.Model):
def place(self):
score = db.func.sum(Challenges.value).label('score')
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
try:
i = teams.index((self.id,)) + 1

View File

@ -14,7 +14,7 @@ def scoreboard_view():
scores = db.session.query(Solves.teamid.label('teamid'), Teams.name.label('name'), score, Solves.date.label('date')) \
.join(Teams) \
.join(Challenges) \
.filter(Teams.banned == None) \
.filter(Teams.banned == False) \
.group_by(Solves.teamid)
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')) \
.join(Teams) \
.join(Challenges) \
.filter(Teams.banned == None) \
.filter(Teams.banned == False) \
.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'))\
@ -79,7 +79,7 @@ def topteams(count):
scores = db.session.query(Solves.teamid.label('teamid'), Teams.name.label('name'), score, Solves.date.label('date')) \
.join(Teams) \
.join(Challenges) \
.filter(Teams.banned == None) \
.filter(Teams.banned == False) \
.group_by(Solves.teamid)
awards = db.session.query(Teams.id.label('teamid'), Teams.name.label('name'),