From 2c4457823e6916ba8586691e10410745efcae5c4 Mon Sep 17 00:00:00 2001 From: Yan Date: Sat, 13 Jan 2024 15:14:33 -0700 Subject: [PATCH] move belt assets helper into utils --- dojo_plugin/api/v1/scoreboard.py | 14 +------------- dojo_plugin/utils/belts.py | 5 +++++ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/dojo_plugin/api/v1/scoreboard.py b/dojo_plugin/api/v1/scoreboard.py index 466e6ed0d..06af198e6 100644 --- a/dojo_plugin/api/v1/scoreboard.py +++ b/dojo_plugin/api/v1/scoreboard.py @@ -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") @@ -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 = ( diff --git a/dojo_plugin/utils/belts.py b/dojo_plugin/utils/belts.py index 004a662c1..62fbdadc8 100644 --- a/dojo_plugin/utils/belts.py +++ b/dojo_plugin/utils/belts.py @@ -1,4 +1,5 @@ from CTFd.cache import cache +from flask import url_for from ..models import Dojos @@ -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():