Adding score and place to team page, fixing create_app

selenium-screenshot-testing
Kevin Chung 2015-03-08 13:39:22 -04:00
parent f43c695330
commit b4dd54d36a
7 changed files with 46 additions and 4 deletions

View File

@ -7,7 +7,7 @@ import logging
import os
import sqlalchemy
def create_app(subdomain, username="", password=""):
def create_app(subdomain="", username="", password=""):
app = Flask("CTFd", static_folder="../static", template_folder="../templates")
with app.app_context():
app.config.from_object('CTFd.config')

View File

@ -277,9 +277,11 @@ def init_admin(app):
user = Teams.query.filter_by(id=teamid).first()
solves = Solves.query.filter_by(teamid=teamid).all()
addrs = Tracking.query.filter_by(team=teamid).group_by(Tracking.ip).all()
score = user.score()
place = user.place()
if request.method == 'GET':
return render_template('admin/team.html', solves=solves, team=user, addrs=addrs)
return render_template('admin/team.html', solves=solves, team=user, addrs=addrs, score=score, place=place)
elif request.method == 'POST':
name = request.form.get('name', None)
password = request.form.get('password', None)

View File

@ -109,6 +109,21 @@ class Teams(db.Model):
def __repr__(self):
return '<team %r>' % self.name
def score(self):
score = db.func.sum(Challenges.value).label('score')
stuff = db.session.query(Solves.teamid, score).join(Teams).join(Challenges).filter(Teams.banned == None, Teams.id==self.id).group_by(Solves.teamid).one()
print stuff
return stuff[1] if stuff[1] else 0
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()
#http://codegolf.stackexchange.com/a/4712
i = teams.index((self.id,)) + 1
k = i%10
return "%d%s"%(i,"tsnrhtdd"[(i/10%10!=1)*(k<4)*k::4])
class Solves(db.Model):
__table_args__ = (db.UniqueConstraint('chalid', 'teamid'), {})
id = db.Column(db.Integer, primary_key=True)

View File

@ -106,10 +106,12 @@ def init_views(app):
def team(teamid):
user = Teams.query.filter_by(id=teamid).first()
solves = Solves.query.filter_by(teamid=teamid).all()
score = user.score()
place = user.place()
db.session.close()
if request.method == 'GET':
return render_template('team.html', solves=solves, team=user)
return render_template('team.html', solves=solves, team=user, score=score, place=place)
elif request.method == 'POST':
json = {'solves':[]}
for x in solves:

View File

@ -1,3 +1,3 @@
from CTFd import create_app
app = create_app('')
app = create_app()
app.run(debug=True, host="0.0.0.0", port=4000)

View File

@ -5,6 +5,17 @@
<div class="row">
<h1 id="team-id">{{ team.name }}</h1>
<h2 id="team-place" class="text-center">
{%if place %}
{{ place }} <small>place</small>
{% endif %}
</h2>
<h2 id="team-score" class="text-center">
{%if score %}
{{ score }} <small>points</small>
{% endif %}
</h2>
<div id="keys-pie-graph"></div>
<div id="categories-pie-graph"></div>

View File

@ -5,6 +5,18 @@
<div class="row">
<h1 id="team-id">{{ team.name }}</h1>
<h2 id="team-place" class="text-center">
{%if place %}
{{ place }} <small>place</small>
{% endif %}
</h2>
<h2 id="team-score" class="text-center">
{%if score %}
{{ score }} <small>points</small>
{% endif %}
</h2>
<br>
<div id="keys-pie-graph"></div>
<div id="categories-pie-graph"></div>