[func] year in template not js [refactor] remove unneeded code

This commit is contained in:
Nikola Kubiczek 2022-04-20 19:28:41 +02:00
parent 7c2d00a657
commit befa154b4e
4 changed files with 19 additions and 12 deletions

View File

@ -9,9 +9,11 @@ from django.db import transaction
from io import BytesIO from io import BytesIO
import xlsxwriter import xlsxwriter
class AnnouncementModelAdmin(SummernoteModelAdmin): class AnnouncementModelAdmin(SummernoteModelAdmin):
summernote_fields = ['content'] summernote_fields = ['content']
class EditionModelAdmin(admin.ModelAdmin): class EditionModelAdmin(admin.ModelAdmin):
list_display = ('__str__', 'active') list_display = ('__str__', 'active')
ordering = ('-active', '-year') ordering = ('-active', '-year')
@ -90,6 +92,7 @@ class EditionModelAdmin(admin.ModelAdmin):
return super().response_change(request, obj) return super().response_change(request, obj)
class StudentModelAdmin(admin.ModelAdmin): class StudentModelAdmin(admin.ModelAdmin):
list_display = ('identifier', '__str__', 'grade') list_display = ('identifier', '__str__', 'grade')
search_fields = ('identifier', 'name', 'surname', 'grade') search_fields = ('identifier', 'name', 'surname', 'grade')

View File

@ -17,7 +17,8 @@ class Edition(models.Model):
award_threshold = models.IntegerField('Próg punktowy - wyróżnienie', default=0) award_threshold = models.IntegerField('Próg punktowy - wyróżnienie', default=0)
laureate_threshold = models.IntegerField('Próg punktowy - tytuł laureata', default=0) laureate_threshold = models.IntegerField('Próg punktowy - tytuł laureata', default=0)
scores = models.FileField('Wyniki do wczytania', blank=True, upload_to='wyniki', help_text='Uwaga! Wyniki muszą być zawarte w pliku .csv. Kolumny po kolei to odpowiednio: identyfikator ucznia, wynik z eliminacji, wynik z finału.') scores = models.FileField('Wyniki do wczytania', blank=True, upload_to='wyniki',
help_text='Uwaga! Wyniki muszą być zawarte w pliku .csv. Kolumny po kolei to odpowiednio: identyfikator ucznia, wynik z eliminacji, wynik z finału.')
first_test = models.FileField('Zadania eliminacyjne', blank=True, upload_to='eliminacje') first_test = models.FileField('Zadania eliminacyjne', blank=True, upload_to='eliminacje')
second_test = models.FileField('Zadania finałowe', blank=True, upload_to='finaly') second_test = models.FileField('Zadania finałowe', blank=True, upload_to='finaly')
@ -51,7 +52,8 @@ class Student(models.Model):
school_town = models.CharField('Miejscowość', max_length=100, blank=True) school_town = models.CharField('Miejscowość', max_length=100, blank=True)
school_address = models.CharField('Adres', max_length=100, blank=True) school_address = models.CharField('Adres', max_length=100, blank=True)
identifier = models.CharField('Identyfikator', max_length=100, blank=True, editable=True, help_text='UWAGA - tej wartości należy nie zmieniać') identifier = models.CharField('Identyfikator', max_length=100, blank=True, editable=True,
help_text='UWAGA - tej wartości należy nie zmieniać')
def __str__(self): def __str__(self):
return f'{self.surname} {self.name}' return f'{self.surname} {self.name}'

View File

@ -75,7 +75,7 @@
</main> </main>
<footer class="footer has-text-centered" style="background-color: transparent !important;"> <footer class="footer has-text-centered" style="background-color: transparent !important;">
<span class="has-text-weight-light is-italic"> <span class="has-text-weight-light is-italic">
&copy; 1998-<script>document.write(new Date().getFullYear());</script> &copy; 1998-{% now "Y" %}
V Liceum Ogólnokształcące w Bielsku-Białej & Mikołaj Kubiczek V Liceum Ogólnokształcące w Bielsku-Białej & Mikołaj Kubiczek
</span> </span>
</footer> </footer>

View File

@ -42,7 +42,8 @@ def SubmitStudentsView(request):
} }
if edition.submissions is not True: if edition.submissions is not True:
queryset = Student.objects.filter(identifier__startswith=f'{edition.year}-{request.user.id}-').order_by('identifier') queryset = Student.objects.filter(
identifier__startswith=f'{edition.year}-{request.user.id}-').order_by('identifier')
return render(request, 'user/submission.html', {'students': queryset, **context}) return render(request, 'user/submission.html', {'students': queryset, **context})
@ -57,7 +58,8 @@ def SubmitStudentsView(request):
students = filter(lambda x: x != {}, formset.cleaned_data) students = filter(lambda x: x != {}, formset.cleaned_data)
for index, data in enumerate(students): for index, data in enumerate(students):
Student.objects.update_or_create(identifier=f'{edition.year}-{request.user.id}-{index + 1}', defaults=data) Student.objects.update_or_create(
identifier=f'{edition.year}-{request.user.id}-{index + 1}', defaults=data)
else: else:
formset = ArticleFormSet(initial=list(map(lambda x: x.__dict__, queryset))) formset = ArticleFormSet(initial=list(map(lambda x: x.__dict__, queryset)))
@ -102,7 +104,7 @@ class TestsView(TemplateView):
return context return context
def ScoresView(request, year = None): 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:
@ -129,12 +131,12 @@ def ScoresView(request, year = None):
}, students) }, students)
schools = list({school['id']: school for school in schools}.values()) schools = list({school['id']: school for school in schools}.values())
individual = map(lambda x: { individual = filter(lambda x: x['score'] >= edition.award_threshold,
**x.__dict__, map(lambda x: {
'score': x.score_first * x.score_second, **x.__dict__,
'title': 'Laureat' if x.score_first * x.score_second >= edition.laureate_threshold else 'Wyróżnienie' 'score': x.score_first * x.score_second,
}, students.filter(score_first__gte=edition.entry_threshold)) 'title': 'Laureat' if x.score_first * x.score_second >= edition.laureate_threshold else 'Wyróżnienie'
individual = filter(lambda x: x['score'] >= edition.award_threshold, individual) }, students.filter(score_first__gte=edition.entry_threshold)))
teams = [] teams = []
for school in schools: for school in schools: