From 31e037f242fa67fc7f847d6128d81b3d57fdb14b Mon Sep 17 00:00:00 2001 From: Anet Date: Thu, 16 Apr 2020 00:51:38 +0200 Subject: [PATCH] =?UTF-8?q?Zprovozn=C4=9Bno=20generov=C3=A1n=C3=AD=20titul?= =?UTF-8?q?=C5=AF.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/templates/seminar/archiv/tituly.tex | 3 +- seminar/urls.py | 4 +- seminar/views/views_all.py | 49 +++++++++++---------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/seminar/templates/seminar/archiv/tituly.tex b/seminar/templates/seminar/archiv/tituly.tex index 72b1cdde..aca444df 100644 --- a/seminar/templates/seminar/archiv/tituly.tex +++ b/seminar/templates/seminar/archiv/tituly.tex @@ -1,6 +1,5 @@ {% if broken %} -%% POZOR! %% Dva resitele maji stejne makro!!! -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +POZOR! Kolize jmen! Dva řešitelé mají stejné makro! {% endif %} {% autoescape off %} diff --git a/seminar/urls.py b/seminar/urls.py index 2db6d367..f0790359 100644 --- a/seminar/urls.py +++ b/seminar/urls.py @@ -87,8 +87,8 @@ urlpatterns = [ path('cislo/./obalky.pdf', staff_member_required(views.cisloObalkyView), name='seminar_cislo_obalky'), - #path('cislo/(?P\d+).(?P[0-9-]+)/tituly.tex', - # staff_member_required(views.TitulyView), name='seminar_cislo_titul'), + path('cislo/./tituly.tex', + staff_member_required(views.TitulyView), name='seminar_cislo_titul'), path('stav', staff_member_required(views.StavDatabazeView), name='stav_databaze'), path('cislo/./obalkovani', diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index 71eeb1b1..5a7025d6 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -855,30 +855,31 @@ def oldObalkovaniView(request, rocnik, cislo): ### Tituly -# TODO udelat neco jako get_objects_or_404 -# FIXME: prepsat, aby nepouzivalo VysledkyK... -#def TitulyView(request, rocnik, cislo): -# rocnik_obj = Rocnik.objects.get(rocnik = rocnik) -# resitele = Resitel.objects.filter(rok_maturity__gte = rocnik_obj.prvni_rok) -# cislo_obj = Cislo.objects.get(rocnik = rocnik_obj, cislo = cislo) -# -# asciijmena = [] -# broken = False -# -# for resitel in resitele: -# 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,'broken':broken},content_type="text/plain") +def TitulyView(request, rocnik, cislo): + rocnik_obj = Rocnik.objects.get(rocnik = rocnik) + resitele = Resitel.objects.filter(rok_maturity__gte = rocnik_obj.prvni_rok) + cislo_obj = Cislo.objects.get(rocnik = rocnik_obj, poradi = cislo) + + asciijmena = [] + jmenovci = False # detekuje, zda jsou dva řešitelé jmenovci (modulo nabodeníčka), pokud ano, vrátí se jako true + slovnik_s_body = body_resitelu_odjakziva(rocnik_obj, resitele) + + for resitel in resitele: + resitel.titul = resitel.get_titul(slovnik_s_body[resitel.id]) + jmeno = resitel.osoba.jmeno+resitel.osoba.prijmeni + # převedeme jména a příjmení řešitelů do ASCII + ascii_jmeno_bytes = unicodedata.normalize('NFKD', jmeno).encode("ascii","ignore") + # vrátí se byte string, převedeme na standardní string + ascii_jmeno_divnoznaky = str(ascii_jmeno_bytes, "utf-8", "ignore").replace(" ","") + resitel.ascii = ''.join(a for a in ascii_jmeno_divnoznaky if a.isalnum()) + if resitel.ascii not in asciijmena: + asciijmena.append(resitel.ascii) + else: + jmenovci = True + + return render(request, 'seminar/archiv/tituly.tex', + {'resitele': resitele,'jmenovci':jmenovci},content_type="text/plain") + ### Soustredeni