Skip to content

Commit

Permalink
fetch belts from the awards table, named BELT_BLUE, BELT_GREEN, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
zardus committed Jan 13, 2024
1 parent 7b816e7 commit b6a8f31
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions dojo_plugin/utils/belts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime

from CTFd.cache import cache
from CTFd.models import Awards
from flask import url_for
from ..models import Dojos

Expand Down Expand Up @@ -43,9 +44,18 @@ def get_belts():
result["dates"][color] = {}
result["ranks"][color] = []

for user,date in dojo.completions():
if date > CUMULATIVE_CUTOFF and result["users"].get(user.id, {"rank_id":-1})["rank_id"] != n-1:
belt_awards = [ (award.user, award.date) for award in Awards.query.filter_by(name="BELT_"+color.upper()) ]
awarded_ids = set(u.id for u,_ in belt_awards)
sorted_belts = sorted(belt_awards + dojo.completions(), key=lambda d: d[1])

for user,date in sorted_belts:
if (
date > CUMULATIVE_CUTOFF and
user.id not in awarded_ids and
result["users"].get(user.id, {"rank_id":-1})["rank_id"] != n-1
):
continue

result["dates"][color][user.id] = str(date)
result["users"][user.id] = {
"handle": user.name,
Expand Down

0 comments on commit b6a8f31

Please sign in to comment.