scoreboard for 42 Network
This commit is contained in:
parent
63876e91ef
commit
8a2cc6f3ae
|
@ -0,0 +1,49 @@
|
||||||
|
{% 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 class="pagination">
|
||||||
|
<span class="step-links">
|
||||||
|
{% if scores.has_previous %}
|
||||||
|
<a href="?page=1">« {% trans "First" %}</a>
|
||||||
|
<a href="?page={{ scores.previous_page_number }}">{% trans "Previous" %}</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<span class="current">
|
||||||
|
{% trans "Page "%} {{ scores.number }} / {{ scores.paginator.num_pages }}.
|
||||||
|
</span>
|
||||||
|
|
||||||
|
{% if scores.has_next %}
|
||||||
|
<a href="?page={{ scores.next_page_number }}">{% trans "Next" %}</a>
|
||||||
|
<a href="?page={{ scores.paginator.num_pages }}">{% trans "Last" %}»</a>
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -4,6 +4,7 @@ from . import views
|
||||||
app_name = "scoreboard"
|
app_name = "scoreboard"
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.scoreboard, name='scoreboard'),
|
path('', views.scoreboard, name='main'),
|
||||||
path('campus/<str:campus>', views.campus, name='campus')
|
path('campus/<str:campus>', views.campus, name='campus'),
|
||||||
|
path('network/', views.network, name='network')
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from accounts.models import UserProfileInfo
|
from accounts.models import UserProfileInfo, Campus
|
||||||
|
|
||||||
def scoreboard(request):
|
def scoreboard(request):
|
||||||
scores = UserProfileInfo.objects.filter(score__gt=0).select_related().order_by('-score', 'last_submission_date', 'user__username')
|
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)
|
scores_p = paginator.get_page(page)
|
||||||
return render(request, 'scoreboard/scoreboard.html', {'scores':scores_p})
|
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.
|
# Create your views here.
|
||||||
|
|
|
@ -58,20 +58,26 @@
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="nav-item">
|
<li class="nav-item dropdown">
|
||||||
<a class="nav-link" href="{% url 'scoreboard:scoreboard' %}">{% translate "Scoreboard" %}</a>
|
<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>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="{% url 'events:events' %}">{% translate "Events" %}</a>
|
<a class="nav-link" href="{% url 'events:events' %}">{% translate "Events" %}</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item dropdown">
|
<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">
|
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
Resources
|
{% trans "Resources" %}
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||||
<a class="dropdown-item" href="{% url 'resources:about' %}">About</a>
|
<a class="dropdown-item" href="{% url 'resources:about' %}">{% trans "About"%}</a>
|
||||||
<a class="dropdown-item" href="{% url 'resources:howToStart' %}">How To Start</a>
|
<a class="dropdown-item" href="{% url 'resources:howToStart' %}">{% trans "How To Start" %}</a>
|
||||||
<a class="dropdown-item" href="{% url 'resources:contribute' %}">Contribute</a>
|
<a class="dropdown-item" href="{% url 'resources:contribute' %}">{% trans "Contribute" %}</a>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in New Issue