diff --git a/src/scoreboard/templates/scoreboard/network.html b/src/scoreboard/templates/scoreboard/network.html new file mode 100644 index 0000000..10c5d85 --- /dev/null +++ b/src/scoreboard/templates/scoreboard/network.html @@ -0,0 +1,49 @@ +{% extends 'base.html' %} +{% load i18n %} +{% block content %} +{% load key_value %} +
+
+
+

Scoreboard

+ + + + + + + + + + {% for name, score in scores.items %} + + + + + + {% endfor %} + +
{% trans "Rank" %}{% trans "Campus" %}{% trans "Score" %}
# {{ forloop.counter0|add:1 }} {{ name }}{{ score}}
+ + + +
+
+
+{% endblock %} diff --git a/src/scoreboard/urls.py b/src/scoreboard/urls.py index 5f95344..26cf2c1 100644 --- a/src/scoreboard/urls.py +++ b/src/scoreboard/urls.py @@ -4,6 +4,7 @@ from . import views app_name = "scoreboard" urlpatterns = [ - path('', views.scoreboard, name='scoreboard'), - path('campus/', views.campus, name='campus') + path('', views.scoreboard, name='main'), + path('campus/', views.campus, name='campus'), + path('network/', views.network, name='network') ] diff --git a/src/scoreboard/views.py b/src/scoreboard/views.py index c5fb031..eb32ef7 100644 --- a/src/scoreboard/views.py +++ b/src/scoreboard/views.py @@ -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. diff --git a/src/templates/base.html b/src/templates/base.html index aedcb11..a631586 100644 --- a/src/templates/base.html +++ b/src/templates/base.html @@ -58,20 +58,26 @@ -