|
|
|
from django.shortcuts import get_object_or_404, render
|
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from django.views import generic
|
|
|
|
from .models import Problem, Cislo, Reseni, VysledkyKCislu, Nastaveni, Rocnik
|
|
|
|
|
|
|
|
|
|
|
|
def AktualZadaniView(request):
|
|
|
|
nastaveni = get_object_or_404(Nastaveni)
|
|
|
|
return render(request, 'seminar/AktualZadani.html',
|
|
|
|
{'nastaveni' : nastaveni,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
class RocnikView(generic.DetailView):
|
|
|
|
model = Rocnik
|
|
|
|
template_name = 'seminar/rocnik.html'
|
|
|
|
|
|
|
|
class ProblemView(generic.DetailView):
|
|
|
|
model = Problem
|
|
|
|
template_name = 'seminar/problem.html'
|
|
|
|
|
|
|
|
class RadekVysledkovky(object):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class CisloView(generic.DetailView):
|
|
|
|
model = Cislo
|
|
|
|
template_name = 'seminar/cislo.html'
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(CisloView, self).get_context_data(**kwargs)
|
|
|
|
|
|
|
|
vysledky = VysledkyKCislu.objects.filter(cislo = context['cislo']).select_related("resitel")
|
|
|
|
reseni = Reseni.objects.filter(cislo_body = context['cislo']).select_related("resitel")
|
|
|
|
|
|
|
|
problemy = sorted(list(set([r.problem for r in reseni])), key=lambda x:x.kod)
|
|
|
|
problem_index = {}
|
|
|
|
for i in range(len(problemy)):
|
|
|
|
problem_index[problemy[i].id] = i
|
|
|
|
|
|
|
|
vysledky_resitele = {}
|
|
|
|
vysledkovka = []
|
|
|
|
posledni_body = 100000
|
|
|
|
for vi in range(len(vysledky)):
|
|
|
|
v = vysledky[vi]
|
|
|
|
tv = RadekVysledkovky()
|
|
|
|
tv.resitel = v.resitel
|
|
|
|
tv.vysledek = v
|
|
|
|
tv.body = ['']*len(problemy)
|
|
|
|
tv.poradi = ''
|
|
|
|
if posledni_body > v.body_celkem:
|
|
|
|
posledni_body = v.body_celkem
|
|
|
|
tv.poradi = vi + 1
|
|
|
|
vysledky_resitele[v.resitel.id] = tv
|
|
|
|
vysledkovka.append(tv)
|
|
|
|
|
|
|
|
for r in reseni:
|
|
|
|
vysledky_resitele[r.resitel.id].body[problem_index[r.problem.id]] = r.body
|
|
|
|
|
|
|
|
context['vysledkovka'] = vysledkovka
|
|
|
|
context['problemy'] = problemy
|
|
|
|
return context
|
|
|
|
|
|
|
|
|