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.views import generic
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.http import Http404
|
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 Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel, Novinky, Soustredeni_Ucastnici
|
||||||
from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva
|
from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva
|
||||||
|
@ -343,28 +344,42 @@ class RocnikVysledkovkaView(RocnikView):
|
||||||
|
|
||||||
### Generovani obalek
|
### Generovani obalek
|
||||||
class CisloObalkyStruct:
|
class CisloObalkyStruct:
|
||||||
resitele = None
|
|
||||||
rocnik = 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()
|
letos = CisloObalkyStruct()
|
||||||
loni = CisloObalkyStruct()
|
loni = CisloObalkyStruct()
|
||||||
|
|
||||||
letos.rocnik = Rocnik.objects.filter(rocnik = rocnik)[0]
|
aktualni_resitele = aktualniResitele(rocnik)
|
||||||
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))
|
letos.rocnik = Rocnik.objects.filter(rocnik = rocnik).first()
|
||||||
loni.problemy = Problem.objects.filter(cislo_zadani = Cislo.objects.filter(rocnik=loni.rocnik))
|
loni.rocnik = Rocnik.objects.filter(rocnik = int(rocnik)-1).first()
|
||||||
letos.resitele = Resitel.objects.filter(reseni = Reseni.objects.filter(problem=letos.problemy)).distinct()
|
letos.cisla = Cislo.objects.filter(rocnik=letos.rocnik,cislo__lte = cislo)
|
||||||
loni.resitele = Resitel.objects.filter(reseni = Reseni.objects.filter(problem=loni.problemy)).distinct()
|
loni.cisla = Cislo.objects.filter(rocnik=loni.rocnik)
|
||||||
|
|
||||||
loni.resitele = loni.resitele.filter(rok_maturity__gt = letos.rocnik.prvni_rok)
|
|
||||||
|
|
||||||
if int(cislo) > 3:
|
if int(cislo) > 3:
|
||||||
resitele = letos.resitele
|
problemy = Problem.objects.filter(cislo_zadani = letos.cisla)
|
||||||
else:
|
else:
|
||||||
resitele = list(letos.resitele) + list(loni.resitele)
|
problemy = Problem.objects.filter(Q(cislo_zadani = letos.cisla)|Q(cislo_zadani=loni.cisla))
|
||||||
return obalkyView(request,resitele)
|
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):
|
def obalkyView(request,resitele):
|
||||||
|
|
Loading…
Reference in a new issue