Skip to content

Commit

Permalink
feat: Display detailed challenge completion info in hacker page
Browse files Browse the repository at this point in the history
  • Loading branch information
CeS-3 authored and zardus committed Jan 30, 2025
1 parent 6eb60a0 commit 1add681
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
15 changes: 14 additions & 1 deletion dojo_plugin/pages/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,25 @@ def view_hacker(user):
.viewable(user=get_current_user())
.filter(Dojos.data["type"] != "hidden", Dojos.data["type"] != "course")
.all())
user_solves = {}
for dojo in dojos:
dojo_id = dojo.id
user_solves[dojo_id] = {}

for module in dojo.modules:
module_id = module.id
solves = module.solves(user=user, ignore_visibility=True, ignore_admins=False) if user else []

if solves:
user_solves[dojo_id][module_id] = {
solve.challenge_id: solve.date.strftime("%Y-%m-%d %H:%M:%S") for solve in solves
}
return render_template(
"hacker.html",
dojos=dojos, user=user,
dojo_scores=dojo_scores(), module_scores=module_scores(),
belts=get_belts(), badges=get_viewable_emojis(user)
belts=get_belts(), badges=get_viewable_emojis(user),
user_solves=user_solves
)

@users.route("/hacker/<int:user_id>")
Expand Down
37 changes: 36 additions & 1 deletion dojo_theme/templates/hacker.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,47 @@ <h4 class="accordion-item-name">{{ module.name }}</h4>
<td>{{ rank or "-" }} / {{ max_rank or "-" }}</td>
</span>
{% else %}
TODO
{% if module.challenges %}
{% for challenge in module.challenges %}
{% set solved = "challenge-solved" if dojo.id in user_solves and module.id in user_solves[dojo.id] and challenge.challenge_id in user_solves[dojo.id][module.id] else "challenge-unsolved" %}
{% if solved == "challenge-solved" %}
<div class="challenge-row">
<div class="challenge-info">
<h4>
<span class="d-sm-block d-md-block d-lg-block">
<i class="fas fa-flag pr-3 {{ solved }}"></i>{{ challenge.name or challenge.id }}
{% if not challenge.visible() %}
<small><small><small>
<i>hidden</i> &mdash; you can see this because you are this dojo's administrator
</small></small></small>
{% endif %}
</span>
</h4>
<h6>Time of First Successful Submission: {{user_solves[dojo.id][module.id][challenge.challenge_id]}}</h6>
</div>
</div>
<br>
{% else %}
{% endif %}
{% endfor %}
{% else %}
{% endif %}
{% endif %}
{% endcall %}
{% endfor %}
</div>
<style>
.challenge-row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 5px 0;
}

.challenge-info {
flex: 1;
}
</style>
<br>
{% endfor %}
{% endblock %}

0 comments on commit 1add681

Please sign in to comment.