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.
195 lines
7.6 KiB
195 lines
7.6 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, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel
|
|
from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva
|
|
from . import utils
|
|
|
|
def AktualniZadaniView(request):
|
|
nastaveni = get_object_or_404(Nastaveni)
|
|
return render(request, 'seminar/zadani/AktualniZadani.html',
|
|
{'nastaveni' : nastaveni,
|
|
},
|
|
)
|
|
|
|
### Co je M&M
|
|
|
|
## Organizatori
|
|
|
|
class CojemamOrganizatoriView(generic.ListView):
|
|
model = Organizator
|
|
template_name='seminar/cojemam/organizatori.html'
|
|
queryset = Organizator.objects.filter(user__is_active=True)
|
|
def get_context_data(self, **kwargs):
|
|
context = super(CojemamOrganizatoriView, self).get_context_data(**kwargs)
|
|
context['aktivni'] = True
|
|
return context
|
|
|
|
class CojemamOrganizatoriStariView(generic.ListView):
|
|
model = Organizator
|
|
template_name='seminar/cojemam/organizatori.html'
|
|
queryset = Organizator.objects.filter(user__is_active=False)
|
|
|
|
### 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 = VysledkyKCisluZaRocnik.objects.filter(cislo = context['cislo']).order_by('-body').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'].rocnik)
|
|
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_celkem_rocnik = v.body
|
|
tv.body_celkem_odjakziva = VysledkyKCisluOdjakziva.objects.get(resitel=v.resitel, cislo=context['cislo']).body
|
|
body_cislo_q = VysledkyZaCislo.objects.filter(resitel=v.resitel, cislo=context['cislo'])
|
|
tv.body_cislo = body_cislo_q[0].body if len(body_cislo_q) > 0 else 0
|
|
tv.body_minule = tv.body_celkem_rocnik - tv.body_cislo
|
|
tv.titul = tv.resitel.titul(tv.body_celkem_odjakziva)
|
|
#pocet bodu do tohoto cisla
|
|
if posledni_body > tv.body_celkem_rocnik:
|
|
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 = tv.body_celkem_rocnik
|
|
tv.poradi = vi + 1
|
|
#poradi se meni jen u resitele s rozdilnym poctem bodu nez mel minuly
|
|
predchozi_poradi = tv
|
|
elif posledni_body == tv.body_celkem_rocnik:
|
|
if not stejne_body.get(tv.body_celkem_rocnik):
|
|
stejne_body[tv.body_celkem_rocnik] = 1
|
|
#pokud klic neexistuje, zalozim novy pro tohoto resitele
|
|
else:
|
|
stejne_body[tv.body_celkem_rocnik] += 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
|
|
|
|
|
|
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'
|
|
|
|
### Status
|
|
|
|
def StavDatabazeView(request):
|
|
# nastaveni = Nastaveni.objects.get()
|
|
problemy = utils.seznam_problemu()
|
|
muzi = Resitel.objects.filter(pohlavi_muz=True)
|
|
zeny = Resitel.objects.filter(pohlavi_muz=False)
|
|
return render(request, 'seminar/stav_databaze.html',
|
|
{
|
|
# 'nastaveni': nastaveni,
|
|
'problemy': problemy,
|
|
|
|
'resitele': Resitel.objects.all(),
|
|
'muzi': muzi,
|
|
'zeny': zeny,
|
|
'jmena_muzu': utils.histogram([r.jmeno for r in muzi]),
|
|
'jmena_zen': utils.histogram([r.jmeno for r in zeny]),
|
|
})
|
|
|