Web M&M
https://mam.matfyz.cz
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.
162 lines
6.2 KiB
162 lines
6.2 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 = VysledkyKCislu.objects.filter(cislo = context['cislo']).order_by('-body_celkem').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:(0 if x.typ==Problem.TYP_ULOHA else 1,x.kod))
|
|
#setridi problemy podle typu a poradi zadani
|
|
problem_index = {}
|
|
for i in range(len(problemy)):
|
|
problem_index[problemy[i].id] = i
|
|
#umoznuje zjistit index podle id problemu
|
|
|
|
vysledky_resitele = {}
|
|
stejne_body = {}
|
|
konec_rozmezi = {}
|
|
vysledkovka = []
|
|
posledni_body = 100000
|
|
predchozi_poradi = None
|
|
body_minule = None
|
|
|
|
for vi in range(len(vysledky)):
|
|
v = vysledky[vi]
|
|
tv = RadekVysledkovky()
|
|
tv.resitel = v.resitel
|
|
tv.rocnik = tv.resitel.rocnik(context['cislo'].datum_vydani)
|
|
tv.vysledek = v
|
|
#odkazuje na VysledkyKCislu
|
|
tv.body = ['']*len(problemy)
|
|
#pole bodu za ulohy
|
|
tv.poradi = ''
|
|
#defaultni poradi je prazdne - kvuli sdilenym mistum
|
|
tv.body_minule = 0
|
|
#pocet bodu do tohoto cisla
|
|
if posledni_body > v.body_celkem:
|
|
if stejne_body.get(posledni_body):
|
|
konec_rozmezi[posledni_body] = int(predchozi_poradi.poradi) + stejne_body[posledni_body]
|
|
#druha hranice sdilenych pozic - zacatek + pocet lidi se stejnymi body
|
|
predchozi_poradi.poradi = '{0}. -- {1}.'.format(predchozi_poradi.poradi,konec_rozmezi[posledni_body])
|
|
#predchozi radek ktery menil pocty bodu bude mit rozsah, pokud bylo vice radku se stejnym poctem bodu
|
|
elif predchozi_poradi :
|
|
predchozi_poradi.poradi = '{0}.'.format(predchozi_poradi.poradi)
|
|
#pokud nebyl rozsah hodnot, pridam tecku za cislo
|
|
posledni_body = v.body_celkem
|
|
tv.poradi = vi + 1
|
|
#poradi se meni jen u resitele s rozdilnym poctem bodu nez mel minuly
|
|
predchozi_poradi = tv
|
|
elif posledni_body == v.body_celkem:
|
|
if not stejne_body.get(v.body_celkem):
|
|
stejne_body[v.body_celkem] = 1
|
|
#pokud klic neexistuje, zalozim novy pro tohoto resitele
|
|
else:
|
|
stejne_body[v.body_celkem] += 1
|
|
#rozsirim pocet resitelu sdilejici stejnou pozici
|
|
vysledky_resitele[v.resitel.id] = tv
|
|
#odkaz na radek vysledkovky patrici danemu resiteli
|
|
vysledkovka.append(tv)
|
|
|
|
for r in reseni:
|
|
vysledky_resitele[r.resitel.id].body[problem_index[r.problem.id]] = r.body
|
|
body_za_cislo = vysledky_resitele[r.resitel.id].vysledek.body
|
|
#body za toto cislo, stejne jako tv.vysledek.body
|
|
body_celkem = vysledky_resitele[r.resitel.id].vysledek.body_celkem
|
|
vysledky_resitele[r.resitel.id].body_minule = body_celkem - body_za_cislo
|
|
|
|
|
|
context['vysledkovka'] = vysledkovka
|
|
context['problemy'] = problemy
|
|
return context
|
|
|
|
### Generovani vysledkovky
|
|
|
|
class CisloVysledkovkaView(CisloView):
|
|
model = Cislo
|
|
template_name = 'seminar/archiv/cislo_vysledkovka.tex'
|
|
#content_type = 'application/x-tex; charset=UTF8'
|
|
#umozni rovnou stahnout TeXovsky dokument
|
|
content_type = 'text/plain; charset=UTF8'
|
|
#vypise na stranku textovy obsah vyTeXane vysledkovky k okopirovani
|
|
|
|
### 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'
|
|
|