better score view before finals
This commit is contained in:
parent
f7c25363f1
commit
e1ff4c6f8e
@ -4,14 +4,14 @@
|
|||||||
|
|
||||||
## Pomoc ze stroną
|
## 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
|
## Instalacja lokalna
|
||||||
|
|
||||||
### Sklonowanie
|
### Sklonowanie
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ git clone https://github.com/yaemiku/puchar
|
$ git clone https://gitlab.com/yaemiku/puchar
|
||||||
```
|
```
|
||||||
|
|
||||||
### Konfiguracja
|
### Konfiguracja
|
||||||
|
@ -16,6 +16,11 @@
|
|||||||
</nav>
|
</nav>
|
||||||
{% if scores_available %}
|
{% if scores_available %}
|
||||||
<div class="hero has-text-centered">
|
<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>
|
<span class="title my-6">Klasyfikacja indywidualna</span>
|
||||||
<table class="hero-body table is-striped is-narrow is-hoverable is-fullwidth">
|
<table class="hero-body table is-striped is-narrow is-hoverable is-fullwidth">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% if students %}
|
{% 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 %}
|
{% else %}
|
||||||
<button class="button is-link mx-auto" type="submit">Zgłoś</button>
|
<button class="button is-link mx-auto" type="submit">Zgłoś</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
22
app/views.py
22
app/views.py
@ -23,6 +23,7 @@ def UpdateAccountView(request):
|
|||||||
form = CustomUserChangeForm(request.POST, instance=request.user)
|
form = CustomUserChangeForm(request.POST, instance=request.user)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
|
request.user.updateTeam()
|
||||||
else:
|
else:
|
||||||
form = CustomUserChangeForm(instance=request.user)
|
form = CustomUserChangeForm(instance=request.user)
|
||||||
|
|
||||||
@ -49,12 +50,15 @@ def SubmitStudentsView(request):
|
|||||||
queryset = Student.objects.filter(
|
queryset = Student.objects.filter(
|
||||||
identifier__startswith=f'{edition.year}-{request.user.id}-').order_by('identifier')
|
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})
|
return render(request, 'user/submission.html', {'students': students, **context})
|
||||||
|
|
||||||
queryset = Student.objects.filter(identifier__startswith=f'{edition.year}-{request.user.id}-')
|
queryset = Student.objects.filter(
|
||||||
ArticleFormSet = formset_factory(StudentForm, extra=3, max_num=3, min_num=0)
|
identifier__startswith=f'{edition.year}-{request.user.id}-')
|
||||||
|
ArticleFormSet = formset_factory(
|
||||||
|
StudentForm, extra=3, max_num=3, min_num=0)
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
@ -66,8 +70,11 @@ def SubmitStudentsView(request):
|
|||||||
for index, data in enumerate(students):
|
for index, data in enumerate(students):
|
||||||
Student.objects.update_or_create(
|
Student.objects.update_or_create(
|
||||||
identifier=f'{edition.year}-{request.user.id}-{index + 1}', defaults=data)
|
identifier=f'{edition.year}-{request.user.id}-{index + 1}', defaults=data)
|
||||||
|
|
||||||
|
request.user.updateTeam()
|
||||||
else:
|
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})
|
return render(request, 'user/submit.html', {'formset': formset, 'students': len(queryset), **context})
|
||||||
else:
|
else:
|
||||||
@ -114,7 +121,8 @@ def ScoresView(request, year=None):
|
|||||||
if year is not None:
|
if year is not None:
|
||||||
edition = get_object_or_404(Edition, year=year)
|
edition = get_object_or_404(Edition, year=year)
|
||||||
else:
|
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:
|
if edition is None:
|
||||||
edition = Edition.objects.order_by('-year').first()
|
edition = Edition.objects.order_by('-year').first()
|
||||||
@ -125,6 +133,7 @@ def ScoresView(request, year=None):
|
|||||||
'scores_page': 'is-active',
|
'scores_page': 'is-active',
|
||||||
'year': year,
|
'year': year,
|
||||||
'scores_available': edition.scores_available or request.user.is_superuser,
|
'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')
|
'editions': Edition.objects.order_by('year')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +155,8 @@ def ScoresView(request, year=None):
|
|||||||
|
|
||||||
teams = []
|
teams = []
|
||||||
for school in schools:
|
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_first = reduce(lambda x, y: x + y.score_first, team, 0)
|
||||||
score_second = reduce(lambda x, y: x + y.score_second, team, 0)
|
score_second = reduce(lambda x, y: x + y.score_second, team, 0)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Django==3.2.5
|
Django
|
||||||
django-cleanup
|
django-cleanup
|
||||||
django-crispy-bulma
|
django-crispy-bulma
|
||||||
psycopg2-binary
|
psycopg2-binary
|
||||||
|
Loading…
Reference in New Issue
Block a user