mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-19 15:04:23 +01:00
Add a raw_query parameter to the standings functions
This commit is contained in:
@@ -8,7 +8,7 @@ from CTFd.utils.modes import get_model
|
|||||||
|
|
||||||
|
|
||||||
@cache.memoize(timeout=60)
|
@cache.memoize(timeout=60)
|
||||||
def get_standings(count=None, admin=False, fields=[]):
|
def get_standings(count=None, admin=False, fields=[], raw_query=False):
|
||||||
"""
|
"""
|
||||||
Get standings as a list of tuples containing account_id, name, and score e.g. [(account_id, team_name, score)].
|
Get standings as a list of tuples containing account_id, name, and score e.g. [(account_id, team_name, score)].
|
||||||
|
|
||||||
@@ -108,16 +108,20 @@ def get_standings(count=None, admin=False, fields=[]):
|
|||||||
"""
|
"""
|
||||||
Only select a certain amount of users if asked.
|
Only select a certain amount of users if asked.
|
||||||
"""
|
"""
|
||||||
if count is None:
|
if count:
|
||||||
standings = standings_query.all()
|
standings = standings_query.limit(count)
|
||||||
else:
|
|
||||||
standings = standings_query.limit(count).all()
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Return the raw query if requested
|
||||||
|
"""
|
||||||
|
if raw_query:
|
||||||
return standings
|
return standings
|
||||||
|
|
||||||
|
return standings.all()
|
||||||
|
|
||||||
|
|
||||||
@cache.memoize(timeout=60)
|
@cache.memoize(timeout=60)
|
||||||
def get_team_standings(count=None, admin=False, fields=[]):
|
def get_team_standings(count=None, admin=False, fields=[], raw_query=False):
|
||||||
scores = (
|
scores = (
|
||||||
db.session.query(
|
db.session.query(
|
||||||
Solves.team_id.label("team_id"),
|
Solves.team_id.label("team_id"),
|
||||||
@@ -188,16 +192,17 @@ def get_team_standings(count=None, admin=False, fields=[]):
|
|||||||
.order_by(sumscores.columns.score.desc(), sumscores.columns.id)
|
.order_by(sumscores.columns.score.desc(), sumscores.columns.id)
|
||||||
)
|
)
|
||||||
|
|
||||||
if count is None:
|
if count:
|
||||||
standings = standings_query.all()
|
standings = standings_query.limit(count)
|
||||||
else:
|
|
||||||
standings = standings_query.limit(count).all()
|
|
||||||
|
|
||||||
|
if raw_query:
|
||||||
return standings
|
return standings
|
||||||
|
|
||||||
|
return standings.all()
|
||||||
|
|
||||||
|
|
||||||
@cache.memoize(timeout=60)
|
@cache.memoize(timeout=60)
|
||||||
def get_user_standings(count=None, admin=False, fields=[]):
|
def get_user_standings(count=None, admin=False, fields=[], raw_query=False):
|
||||||
scores = (
|
scores = (
|
||||||
db.session.query(
|
db.session.query(
|
||||||
Solves.user_id.label("user_id"),
|
Solves.user_id.label("user_id"),
|
||||||
@@ -267,9 +272,10 @@ def get_user_standings(count=None, admin=False, fields=[]):
|
|||||||
.order_by(sumscores.columns.score.desc(), sumscores.columns.id)
|
.order_by(sumscores.columns.score.desc(), sumscores.columns.id)
|
||||||
)
|
)
|
||||||
|
|
||||||
if count is None:
|
if count:
|
||||||
standings = standings_query.all()
|
standings = standings_query.limit(count)
|
||||||
else:
|
|
||||||
standings = standings_query.limit(count).all()
|
|
||||||
|
|
||||||
|
if raw_query:
|
||||||
return standings
|
return standings
|
||||||
|
|
||||||
|
return standings.all()
|
||||||
|
|||||||
Reference in New Issue
Block a user