Skip to content

Commit

Permalink
move belt assets helper into utils
Browse files Browse the repository at this point in the history
  • Loading branch information
zardus committed Jan 13, 2024
1 parent 404baa4 commit 2c44578
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
14 changes: 1 addition & 13 deletions dojo_plugin/api/v1/scoreboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ...models import Dojos, DojoChallenges, DojoUsers, DojoMembers, DojoAdmins, DojoStudents, DojoModules, DojoChallengeVisibilities
from ...utils import dojo_standings, user_dojos, first_bloods, daily_solve_counts
from ...utils.dojo import dojo_route, dojo_accessible
from ...utils.belts import get_belts
from ...utils.belts import get_belts, belt_asset

SCOREBOARD_CACHE_TIMEOUT_SECONDS = 60 * 60 * 2 # two hours make to cache all scoreboards
scoreboard_namespace = Namespace("scoreboard")
Expand All @@ -34,18 +34,6 @@ def email_symbol_asset(email):
group = "hacker.png"
return url_for("views.themes", path=f"img/dojo/{group}")


def belt_asset(color):
if color == "black":
belt = "black.svg"
elif color == "blue":
belt = "blue.svg"
elif color == "yellow":
belt = "yellow.svg"
else:
belt = "white.svg"
return url_for("views.themes", path=f"img/dojo/{belt}")

@cache.memoize(timeout=SCOREBOARD_CACHE_TIMEOUT_SECONDS)
def get_scoreboard_for(model, duration):
duration_filter = (
Expand Down
5 changes: 5 additions & 0 deletions dojo_plugin/utils/belts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from CTFd.cache import cache
from flask import url_for
from ..models import Dojos


Expand All @@ -9,6 +10,10 @@
"blue": "software-exploitation",
}

def belt_asset(color):
belt = color + ".svg" if color in BELT_REQUIREMENTS else "white.svg"
return url_for("views.themes", path=f"img/dojo/{belt}")

def get_user_belts(user):
result = [ ]
for belt, dojo_id in BELT_REQUIREMENTS.items():
Expand Down

0 comments on commit 2c44578

Please sign in to comment.