diff --git a/hackathon/templates/hackathon/final_score.html b/hackathon/templates/hackathon/final_score.html
new file mode 100644
index 00000000..2f3aedf5
--- /dev/null
+++ b/hackathon/templates/hackathon/final_score.html
@@ -0,0 +1,26 @@
+{% extends "base.html" %}
+{% load static %}
+{% block content %}
+
{{ hackathon }}
Final Scores
+ {% if sorted_teams_scores %}
+
+
+
+ Project |
+ Score |
+
+
+
+ {% for team in sorted_teams_scores %}
+
+ {{ team.0 }} |
+ {{ team.1 }} |
+
+ {% endfor %}
+
+
+ {% else %}
+ There are no final scores for this Hackathon.
+ {% endif %}
+ {% endblock %}
+
\ No newline at end of file
diff --git a/hackathon/urls.py b/hackathon/urls.py
index c47eb443..8caa9013 100644
--- a/hackathon/urls.py
+++ b/hackathon/urls.py
@@ -6,12 +6,14 @@
delete_hackathon,
HackathonDetailView,
enroll_toggle,
- judging
+ judging,
+ check_projects_scores
)
urlpatterns = [
path('', HackathonListView.as_view(), name="hackathon-list"),
path("/team//judging/", judging, name="judging"),
+ path("/final_score", check_projects_scores, name="final_score"),
path("create_hackathon", create_hackathon, name='create_hackathon'),
path("/update_hackathon", update_hackathon, name="update_hackathon"),
path("/delete_hackathon", delete_hackathon, name="delete_hackathon"),
diff --git a/hackathon/views.py b/hackathon/views.py
index 95b95e07..4b3792b5 100644
--- a/hackathon/views.py
+++ b/hackathon/views.py
@@ -7,7 +7,7 @@
from django.http import JsonResponse, HttpResponse
from django.utils import timezone
-from .models import Hackathon, HackTeam, HackProject, HackProjectScore, HackProjectScoreCategory
+from .models import Hackathon, HackTeam, HackProject, HackProjectScore, HackProjectScoreCategory, HackAwardCategory
from .forms import HackathonForm
@@ -84,7 +84,7 @@ def judging(request, hack_id, team_id):
hack_project_score_category=score_category,
)
team_score.save()
- check_projects_scores(hackathon, score_categories)
+ return check_projects_scores(request, hack_id)
context = {
'hackathon': hackathon,
@@ -95,11 +95,20 @@ def judging(request, hack_id, team_id):
return render(request, 'hackathon/judging.html', context)
-def check_projects_scores(hackathon, score_categories):
+@login_required
+def check_projects_scores(request, hack_id):
""" When a judge submits the score, check if all projects in the Hackathon
were scored by all the judges in all the categories by comparing the number of
- objects in HackProjectScore for each projects to the required number of objects """
+ objects in HackProjectScore for each projects to the required number of objects.
+
+ If all projects weren't scored, render final_score.html without the score table.
+
+ If all the projects were scored, calculate the total score for each team, sort the teams by scores
+ and render final_score.html with the score table.
+ """
+ score_categories = HackProjectScoreCategory.objects.all()
+ hackathon = get_object_or_404(Hackathon, pk=hack_id)
judges = hackathon.judges.count()
number_categories = score_categories.count()
projects = list(HackTeam.objects.filter(
@@ -109,12 +118,26 @@ def check_projects_scores(hackathon, score_categories):
number_of_objects = judges * number_categories
for project in projects:
- if HackProjectScore.objects.filter(project=project).count() == number_of_objects:
- continue
- else:
- return redirect("hackathon:hackathon-list")
+ if HackProjectScore.objects.filter(project=project).count() != number_of_objects:
+ return render(request, 'hackathon/final_score.html', {"hackathon": hackathon.display_name})
+
+ # Calculate total score for each team
+ scores_list = []
+ for project in projects:
+ total_score = sum(list(HackProjectScore.objects.filter(
+ project=project).values_list("score", flat=True)))
+ scores_list.append(total_score)
+
+ # Pair the teams with the total score
+ team_scores = {}
+ for i, score in enumerate(scores_list):
+ team_scores[str(HackProject.objects.get(id=projects[i]))] = score
+
+ # Sort the teams by score
+ sorted_teams_scores = sorted(
+ team_scores.items(), key=lambda x: x[1], reverse=True)
- # Call a function to calculate the scores and redirect to a view that will show a list of all of the projects ranked by their score
+ return render(request, 'hackathon/final_score.html', {'sorted_teams_scores': sorted_teams_scores, "hackathon": hackathon.display_name})
def create_hackathon(request):
diff --git a/static/css/style.css b/static/css/style.css
index c08644a5..30d50bc6 100644
--- a/static/css/style.css
+++ b/static/css/style.css
@@ -247,6 +247,35 @@ html .all-auth-container {
text-align: left;
}
+/* Final Score page */
+
+tbody >:first-child {
+ background-color: var(--p-orange);
+ color: var(--white);
+}
+
+.table_titles, .final_score_table {
+ text-align: center;
+}
+
+h1.table_titles{
+ margin-bottom: 5vh;
+ font-size: 6vh;
+}
+
+.final_score_table {
+ width: 75%;
+ margin: 5vh auto;
+ border: 1px solid var(--p-grey);
+}
+
+.final_score_table tr {
+ border-bottom: 1px solid var(--p-grey);
+}
+
+.final_score_table tr th {
+ padding: 2vh
+}
.bg-p-blue {
background-color: var(--p-blue);