From 8a2cc6f3aed0ad21e82ddcd3cdcd79936ad6f93d Mon Sep 17 00:00:00 2001 From: Danhia Date: Wed, 17 Aug 2022 12:59:29 +0200 Subject: [PATCH 1/3] scoreboard for 42 Network --- .../templates/scoreboard/network.html | 49 +++++++++++++++++++ src/scoreboard/urls.py | 5 +- src/scoreboard/views.py | 13 ++++- src/templates/base.html | 18 ++++--- 4 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 src/scoreboard/templates/scoreboard/network.html 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 @@ - From d21915405ed11e7006bd32104e785f33ed5dc614 Mon Sep 17 00:00:00 2001 From: Danhia Date: Wed, 17 Aug 2022 22:58:36 +0200 Subject: [PATCH 2/3] removed pagination on network scoreboard --- .../templates/scoreboard/network.html | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/scoreboard/templates/scoreboard/network.html b/src/scoreboard/templates/scoreboard/network.html index 10c5d85..afdb342 100644 --- a/src/scoreboard/templates/scoreboard/network.html +++ b/src/scoreboard/templates/scoreboard/network.html @@ -24,25 +24,6 @@ {% endfor %} - - - From 09118cac7a2a9eced2796e9c673c8cb1b22b9a03 Mon Sep 17 00:00:00 2001 From: Danhia Date: Thu, 18 Aug 2022 10:38:53 +0200 Subject: [PATCH 3/3] removed the is_member attribute for campus name --- src/scoreboard/templates/scoreboard/network.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/scoreboard/templates/scoreboard/network.html b/src/scoreboard/templates/scoreboard/network.html index afdb342..1d876d5 100644 --- a/src/scoreboard/templates/scoreboard/network.html +++ b/src/scoreboard/templates/scoreboard/network.html @@ -1,7 +1,6 @@ {% extends 'base.html' %} {% load i18n %} {% block content %} -{% load key_value %}
@@ -18,7 +17,7 @@ {% for name, score in scores.items %} # {{ forloop.counter0|add:1 }} - {{ name }} + {{ name }} {{ score}} {% endfor %}