From 8e8474920fb5c8c824d75ca548ff04f19e7ef0af Mon Sep 17 00:00:00 2001 From: yaemiku Date: Mon, 25 Apr 2022 16:15:52 +0000 Subject: [PATCH] [func] don't show shchools without points [func] show ranking and scores for teachers --- app/templates/user/submission.html | 16 ++++++++++++++-- app/views.py | 11 +++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/templates/user/submission.html b/app/templates/user/submission.html index bac8e76..ee0bc27 100644 --- a/app/templates/user/submission.html +++ b/app/templates/user/submission.html @@ -13,12 +13,18 @@ Identyfikator Uczeń Klasa + {% if ongoing.scores_available %} + Zajęte miejsce + Wynik z finału + Wynik z eliminacji + {% else %} {% if ongoing.scores_eliminations %} Liczba punktów zdobytych podczas eliminacji {% if ongoing.entry_threshold > 0 %} Wynik eliminacji {% endif %} - {%endif %} + {% endif %} + {% endif %} {% for student in students %} @@ -27,6 +33,11 @@ {{ student.identifier }} {{ student.name }} {{ student.surname }} {{ student.grade }} + {% if ongoing.scores_available %} + {{ student.ranking }} + {{ student.score_second }} + {{ student.score_first }} + {% else %} {% if ongoing.scores_eliminations %} {{ student.score_first | default:"-" }} @@ -41,6 +52,7 @@ {% endif %} {% endif %} + {% endif %} {% endfor %} @@ -51,4 +63,4 @@ Żaden uczeń nie został zgłoszony {% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/views.py b/app/views.py index 3bfbccb..a31bb80 100644 --- a/app/views.py +++ b/app/views.py @@ -42,10 +42,16 @@ def SubmitStudentsView(request): } if edition.submissions is not True: + ranking = {} + for index, student in enumerate(sorted(Student.objects.filter(identifier__startswith=f'{edition.year}-'), key=lambda x: x.score_first*x.score_second, reversed=True)): + ranking[student.identifier] = index + 1 + queryset = Student.objects.filter( identifier__startswith=f'{edition.year}-{request.user.id}-').order_by('identifier') - return render(request, 'user/submission.html', {'students': queryset, **context}) + students = [{**student.__dict__, 'ranking': ranking[student.identifier]} for queryset] + + return render(request, 'user/submission.html', {'students': students, **context}) queryset = Student.objects.filter(identifier__startswith=f'{edition.year}-{request.user.id}-') ArticleFormSet = formset_factory(StudentForm, extra=3, max_num=3, min_num=0) @@ -145,7 +151,8 @@ def ScoresView(request, year=None): score_first = reduce(lambda x, y: x + y.score_first, team, 0) score_second = reduce(lambda x, y: x + y.score_second, team, 0) - teams.append({**school, 'score': score_first * score_second}) + if score_first*score_second > 0: + teams.append({**school, 'score': score_first * score_second}) context = { 'individual': sorted(individual, key=lambda x: -x['score']),