better score view before finals

This commit is contained in:
Nikola Kubiczek 2023-03-20 18:00:41 +01:00
parent f7c25363f1
commit e1ff4c6f8e
5 changed files with 25 additions and 10 deletions

View File

@ -4,14 +4,14 @@
## Pomoc ze stroną
Kod jest dostępny publicznie w celu ulepszania strony. Jeśli chcesz wprowadzić nową funkcję lub poprawkę, jestem otwarty na zmiany.
Kod jest dostępny publicznie w celu ulepszania strony. Jeśli chcesz wprowadzić nową funkcję lub poprawkę, jestem otwarta na zmiany.
## Instalacja lokalna
### Sklonowanie
```bash
$ git clone https://github.com/yaemiku/puchar
$ git clone https://gitlab.com/yaemiku/puchar
```
### Konfiguracja

View File

@ -16,6 +16,11 @@
</nav>
{% if scores_available %}
<div class="hero has-text-centered">
{% if admin_preview %}
<div class="notification is-danger is-light my-2">
<span class="subtitle ">Podgląd administratora</span>
</div>
{% endif %}
<span class="title my-6">Klasyfikacja indywidualna</span>
<table class="hero-body table is-striped is-narrow is-hoverable is-fullwidth">
<thead>

View File

@ -25,7 +25,7 @@
{% endfor %}
{% if students %}
<button class="button is-info mx-auto" type="submit">Edytuj</button>
<button class="button is-info mx-auto" type="submit">Zapisz zmiany</button>
{% else %}
<button class="button is-link mx-auto" type="submit">Zgłoś</button>
{% endif %}

View File

@ -23,6 +23,7 @@ def UpdateAccountView(request):
form = CustomUserChangeForm(request.POST, instance=request.user)
if form.is_valid():
form.save()
request.user.updateTeam()
else:
form = CustomUserChangeForm(instance=request.user)
@ -49,12 +50,15 @@ def SubmitStudentsView(request):
queryset = Student.objects.filter(
identifier__startswith=f'{edition.year}-{request.user.id}-').order_by('identifier')
students = [{**student.__dict__, 'ranking': ranking[student.identifier]} for student in queryset]
students = [{**student.__dict__, 'ranking': ranking[student.identifier]}
for student in 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)
queryset = Student.objects.filter(
identifier__startswith=f'{edition.year}-{request.user.id}-')
ArticleFormSet = formset_factory(
StudentForm, extra=3, max_num=3, min_num=0)
if request.method == 'POST':
with transaction.atomic():
@ -66,8 +70,11 @@ def SubmitStudentsView(request):
for index, data in enumerate(students):
Student.objects.update_or_create(
identifier=f'{edition.year}-{request.user.id}-{index + 1}', defaults=data)
request.user.updateTeam()
else:
formset = ArticleFormSet(initial=list(map(lambda x: x.__dict__, queryset)))
formset = ArticleFormSet(initial=list(
map(lambda x: x.__dict__, queryset)))
return render(request, 'user/submit.html', {'formset': formset, 'students': len(queryset), **context})
else:
@ -114,7 +121,8 @@ def ScoresView(request, year=None):
if year is not None:
edition = get_object_or_404(Edition, year=year)
else:
edition = Edition.objects.filter(scores_available=True).order_by('-year').first()
edition = Edition.objects.filter(
scores_available=True).order_by('-year').first()
if edition is None:
edition = Edition.objects.order_by('-year').first()
@ -125,6 +133,7 @@ def ScoresView(request, year=None):
'scores_page': 'is-active',
'year': year,
'scores_available': edition.scores_available or request.user.is_superuser,
'admin_preview': (not edition.scores_available) and request.user.is_superuser,
'editions': Edition.objects.order_by('year')
}
@ -146,7 +155,8 @@ def ScoresView(request, year=None):
teams = []
for school in schools:
team = students.filter(identifier__startswith=f'{year}-' + school['id'] + '-')
team = students.filter(
identifier__startswith=f'{year}-' + school['id'] + '-')
score_first = reduce(lambda x, y: x + y.score_first, team, 0)
score_second = reduce(lambda x, y: x + y.score_second, team, 0)

View File

@ -1,4 +1,4 @@
Django==3.2.5
Django
django-cleanup
django-crispy-bulma
psycopg2-binary