Funkce pro aktualni a aktivni resitele.
This commit is contained in:
parent
09149f6fc9
commit
96161c4974
1 changed files with 30 additions and 15 deletions
|
@ -7,6 +7,7 @@ from django.core.urlresolvers import reverse
|
|||
from django.views import generic
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.http import Http404
|
||||
from django.db.models import Q
|
||||
|
||||
from .models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel, Novinky, Soustredeni_Ucastnici
|
||||
from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva
|
||||
|
@ -343,28 +344,42 @@ class RocnikVysledkovkaView(RocnikView):
|
|||
|
||||
### Generovani obalek
|
||||
class CisloObalkyStruct:
|
||||
resitele = None
|
||||
rocnik = None
|
||||
problemy = None
|
||||
cisla = None
|
||||
|
||||
def cisloObalkyView(request,rocnik,cislo):
|
||||
|
||||
# Vraci QuerySet aktualnich resitelu = nekdy neco poslali, ale jeste neodmaturovali
|
||||
def aktualniResitele(rocnik):
|
||||
letos = Rocnik.objects.filter(rocnik = rocnik).first()
|
||||
return Resitel.objects.filter(rok_maturity__gt = letos.prvni_rok)
|
||||
# # ALERT: pokud nekdo nema vypleny rok maturity, tak neni aktualni, protoze Karel Tesar a jini
|
||||
# return Resitel.objects.filter(Q(rok_maturity__gt = letos.prvni_rok)|Q(rok_maturity = None))
|
||||
|
||||
# Vraci QuerySet aktivnich resitelu =
|
||||
# jeste neodmaturovali &&
|
||||
# (pokud je aktualni cislo mensi nez 3, pak (letos || loni) neco poslali
|
||||
# jinak letos neco poslali)
|
||||
def aktivniResitele(rocnik,cislo):
|
||||
letos = CisloObalkyStruct()
|
||||
loni = CisloObalkyStruct()
|
||||
|
||||
letos.rocnik = Rocnik.objects.filter(rocnik = rocnik)[0]
|
||||
loni.rocnik = Rocnik.objects.filter(rocnik = int(rocnik)-1)[0]
|
||||
letos.problemy = Problem.objects.filter(cislo_zadani = Cislo.objects.filter(rocnik=letos.rocnik,cislo__lte = cislo))
|
||||
loni.problemy = Problem.objects.filter(cislo_zadani = Cislo.objects.filter(rocnik=loni.rocnik))
|
||||
letos.resitele = Resitel.objects.filter(reseni = Reseni.objects.filter(problem=letos.problemy)).distinct()
|
||||
loni.resitele = Resitel.objects.filter(reseni = Reseni.objects.filter(problem=loni.problemy)).distinct()
|
||||
|
||||
loni.resitele = loni.resitele.filter(rok_maturity__gt = letos.rocnik.prvni_rok)
|
||||
|
||||
aktualni_resitele = aktualniResitele(rocnik)
|
||||
|
||||
letos.rocnik = Rocnik.objects.filter(rocnik = rocnik).first()
|
||||
loni.rocnik = Rocnik.objects.filter(rocnik = int(rocnik)-1).first()
|
||||
letos.cisla = Cislo.objects.filter(rocnik=letos.rocnik,cislo__lte = cislo)
|
||||
loni.cisla = Cislo.objects.filter(rocnik=loni.rocnik)
|
||||
if int(cislo) > 3:
|
||||
resitele = letos.resitele
|
||||
problemy = Problem.objects.filter(cislo_zadani = letos.cisla)
|
||||
else:
|
||||
resitele = list(letos.resitele) + list(loni.resitele)
|
||||
return obalkyView(request,resitele)
|
||||
problemy = Problem.objects.filter(Q(cislo_zadani = letos.cisla)|Q(cislo_zadani=loni.cisla))
|
||||
resitele = aktualni_resitele.filter(reseni = Reseni.objects.filter(problem=problemy)).distinct()
|
||||
|
||||
return resitele
|
||||
|
||||
|
||||
def cisloObalkyView(request,rocnik,cislo):
|
||||
return obalkyView(request,aktivniResitele(rocnik,cislo))
|
||||
|
||||
|
||||
def obalkyView(request,resitele):
|
||||
|
|
Loading…
Reference in a new issue