You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

125 lines
4.4 KiB

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 django.utils.translation import ugettext as _
from django.http import Http404
from .models import Problem, Cislo, Reseni, VysledkyKCislu, Nastaveni, Rocnik, Soustredeni, Organizator
def AktualniZadaniView(request):
nastaveni = get_object_or_404(Nastaveni)
return render(request, 'seminar/zadani/AktualniZadani.html',
{'nastaveni' : nastaveni,
},
)
### Co je M&M
class CojemamOrganizatoriView(generic.ListView):
model = Organizator
template_name='seminar/cojemam/organizatori.html'
### Archiv
class CislaView(generic.ListView):
model = Rocnik
template_name='seminar/archiv/cisla.html'
class RocnikView(generic.DetailView):
model = Rocnik
template_name = 'seminar/archiv/rocnik.html'
# Vlastni ziskavani objektu z databaze podle (Rocnik.rocnik)
def get_object(self, queryset=None):
if queryset is None:
queryset = self.get_queryset()
rocnik_arg = self.kwargs.get('rocnik')
queryset = queryset.filter(rocnik=rocnik_arg)
try:
obj = queryset.get()
except queryset.model.DoesNotExist:
raise Http404(_("No %(verbose_name)s found matching the query") %
{'verbose_name': queryset.model._meta.verbose_name})
return obj
class ProblemView(generic.DetailView):
model = Problem
template_name = 'seminar/archiv/problem.html'
class RadekVysledkovky(object):
pass
class CisloView(generic.DetailView):
model = Cislo
template_name = 'seminar/archiv/cislo.html'
# Vlastni ziskavani objektu z databaze podle (Rocnik.rocnik)
def get_object(self, queryset=None):
if queryset is None:
queryset = self.get_queryset()
rocnik_arg = self.kwargs.get('rocnik')
cislo_arg = self.kwargs.get('cislo')
queryset = queryset.filter(rocnik__rocnik=rocnik_arg, cislo=cislo_arg)
try:
obj = queryset.get()
except queryset.model.DoesNotExist:
raise Http404(_("No %(verbose_name)s found matching the query") %
{'verbose_name': queryset.model._meta.verbose_name})
return obj
def get_context_data(self, **kwargs):
context = super(CisloView, self).get_context_data(**kwargs)
# Vysledky k cislu: seznam objektu typu (cislo, resitel, body [v tom cisle], body_celkem [od zac. rocniku])
vysledky = VysledkyKCislu.objects.filter(cislo = context['cislo']).order_by('-body_celkem').select_related("resitel")
reseni = Reseni.objects.filter(cislo_body = context['cislo']).select_related("resitel")
# seznam problemu s nejakymi body v tomto cisle
problemy = sorted(list(set([r.problem for r in reseni])), key=lambda x:(0 if x.typ==Problem.TYP_ULOHA else 1,x.kod))
# cislo sloupecku pro problem (inverzni funkce)
problem_index = {}
for i in range(len(problemy)):
problem_index[problemy[i].id] = i
# pomocna mapa Resitel: RadekVysledkovky
vysledky_resitele = {}
# radky vysledkovky, seznam objektu RadekVysledkovky
vysledkovka = []
# posledni pocet bodu, pro detekci stejnych mist
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) # misto pro body za jednotlive uloy
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)
# doplneni bodu za jednotliva reseni lidi do RadekVysledkovky.body
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
### Soustredeni
class SoustredeniListView(generic.ListView):
model = Soustredeni
template_name = 'seminar/soustredeni/seznam_soustredeni.html'
class SoustredeniView(generic.DetailView):
model = Soustredeni
template_name = 'seminar/archiv/soustredeni.html'