Scoreboard for 42 Network #73

Merged
Danhia merged 2 commits from Danhia/website:scoreboard/42network into main 2022-08-17 22:59:40 +02:00
4 changed files with 57 additions and 9 deletions

View File

@ -0,0 +1,30 @@
{% extends 'base.html' %}
{% load i18n %}
{% block content %}
{% load key_value %}
<div class="row">
<div class="col-12">
<div>
<h4>Scoreboard</h4>
<table class="table table-dark">
<thead>
<tr>
<th scope="col">{% trans "Rank" %}</th>
<th scope="col">{% trans "Campus" %}</th>
<th scope="col">{% trans "Score" %}</th>
</tr>
</thead>
<tbody>
{% for name, score in scores.items %}
<tr>
<th scope="row"># {{ forloop.counter0|add:1 }}</th>
<th><a class="profile_link {{is_member}}" href="{% url 'scoreboard:campus' campus=name %}"> {{ name }}</a></th>
<td>{{ score}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
Danhia marked this conversation as resolved
Review

You can remove all the pagination div, you don't use it in the network view.

You can remove all the pagination div, you don't use it in the network view.
Review

Done here

Done [here](https://gitea.42ctf.org/42CTF/website/commit/d21915405ed11e7006bd32104e785f33ed5dc614)
</div>
{% endblock %}

View File

@ -4,6 +4,7 @@ from . import views
app_name = "scoreboard"
urlpatterns = [
path('', views.scoreboard, name='scoreboard'),
path('campus/<str:campus>', views.campus, name='campus')
path('', views.scoreboard, name='main'),
path('campus/<str:campus>', views.campus, name='campus'),
path('network/', views.network, name='network')
]

View File

@ -1,6 +1,6 @@
from django.shortcuts import render
from django.core.paginator import Paginator
from accounts.models import UserProfileInfo
from accounts.models import UserProfileInfo, Campus
def scoreboard(request):
scores = UserProfileInfo.objects.filter(score__gt=0).select_related().order_by('-score', 'last_submission_date', 'user__username')
@ -16,4 +16,15 @@ def campus(request, campus):
scores_p = paginator.get_page(page)
return render(request, 'scoreboard/scoreboard.html', {'scores':scores_p})
def network(request):
campuses = Campus.objects.all()
scores = {}
for campus in campuses:
users = UserProfileInfo.objects.filter(score__gt=0, campus__name__exact=campus).select_related().order_by('-score', 'last_submission_date', 'user__username')[:10]
scores[campus] = sum([u.score for u in users])
sorted_scores = {k: v for k, v in sorted(scores.items(), key=lambda item: item[1], reverse=True)}
return render(request, 'scoreboard/network.html', {'scores':sorted_scores})
# Create your views here.

View File

@ -58,20 +58,26 @@
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'scoreboard:scoreboard' %}">{% translate "Scoreboard" %}</a>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{% trans "Scoreboard" %}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{% url 'scoreboard:main' %}">{% trans "Main" %}</a>
<a class="dropdown-item" href="{% url 'scoreboard:network' %}">{% trans "42 Network" %}</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'events:events' %}">{% translate "Events" %}</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Resources
{% trans "Resources" %}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{% url 'resources:about' %}">About</a>
<a class="dropdown-item" href="{% url 'resources:howToStart' %}">How To Start</a>
<a class="dropdown-item" href="{% url 'resources:contribute' %}">Contribute</a>
<a class="dropdown-item" href="{% url 'resources:about' %}">{% trans "About"%}</a>
<a class="dropdown-item" href="{% url 'resources:howToStart' %}">{% trans "How To Start" %}</a>
<a class="dropdown-item" href="{% url 'resources:contribute' %}">{% trans "Contribute" %}</a>
</div>
</li>
</ul>