From fb4edae7e9afc03ff9c6e14d538fdee62e51825a Mon Sep 17 00:00:00 2001 From: Tomas 'Jethro' Pokorny Date: Wed, 6 Jan 2016 23:08:22 +0100 Subject: [PATCH] Tituly varuji pri duplicite + filter+first -> get. --- seminar/templates/seminar/archiv/tituly.tex | 5 ++++ seminar/views.py | 27 +++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/seminar/templates/seminar/archiv/tituly.tex b/seminar/templates/seminar/archiv/tituly.tex index 323cf3b5..0720e736 100644 --- a/seminar/templates/seminar/archiv/tituly.tex +++ b/seminar/templates/seminar/archiv/tituly.tex @@ -1,3 +1,8 @@ +{% if broken %} +%% POZOR! %% Dva resitele maji stejne makro!!! +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +{% endif %} + {% autoescape off %} {% load tex %} diff --git a/seminar/views.py b/seminar/views.py index 5049cd66..cdc5217a 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -356,7 +356,7 @@ class CisloObalkyStruct: # Vraci QuerySet aktualnich resitelu = nekdy neco poslali, ale jeste neodmaturovali def aktualniResitele(rocnik): - letos = Rocnik.objects.filter(rocnik = rocnik).first() + letos = Rocnik.objects.get(rocnik = rocnik) 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)) @@ -371,8 +371,8 @@ def aktivniResitele(rocnik,cislo): aktualni_resitele = aktualniResitele(rocnik) - letos.rocnik = Rocnik.objects.filter(rocnik = rocnik).first() - loni.rocnik = Rocnik.objects.filter(rocnik = int(rocnik)-1).first() + letos.rocnik = Rocnik.objects.get(rocnik = rocnik) + loni.rocnik = Rocnik.objects.get(rocnik = int(rocnik)-1) letos.cisla = Cislo.objects.filter(rocnik=letos.rocnik,cislo__lte = cislo) loni.cisla = Cislo.objects.filter(rocnik=loni.rocnik) if int(cislo) > 3: @@ -430,20 +430,27 @@ def resitelUlohaView(request,rocnik,cislo): # TODO udelat neco jako get_objects_or_404 def TitulyView(request, rocnik, cislo): - rocnik_obj = Rocnik.objects.filter(rocnik = rocnik).first() + rocnik_obj = Rocnik.objects.get(rocnik = rocnik) resitele = Resitel.objects.filter(rok_maturity__gte = rocnik_obj.prvni_rok) - cislo_obj = Cislo.objects.filter(rocnik = rocnik_obj, cislo = cislo).first() + cislo_obj = Cislo.objects.get(rocnik = rocnik_obj, cislo = cislo) + + asciijmena = [] + broken = False for resitel in resitele: - vys = VysledkyKCisluOdjakziva.objects.filter(resitel = resitel, cislo = cislo_obj).first() - if vys == None: - body = 0 - else: + try: + vys = VysledkyKCisluOdjakziva.objects.get(resitel = resitel, cislo = cislo_obj) body = vys.body + except ObjectDoesNotExist: + body = 0 resitel.titul = resitel.get_titul(body) resitel.ascii = unicodedata.normalize('NFKD',resitel.jmeno+resitel.prijmeni).encode("ascii","ignore").replace(" ","") + if resitel.ascii not in asciijmena: + asciijmena.append(resitel.ascii) + else: + broken = True - return render(request, 'seminar/archiv/tituly.tex',{'resitele': resitele}) + return render(request, 'seminar/archiv/tituly.tex',{'resitele': resitele,'broken':broken}) ### Soustredeni