From 98c6f2053d8cd26d8874cc96d96a28a14b84bfe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Wed, 23 Sep 2015 18:16:17 +0200 Subject: [PATCH] =?UTF-8?q?Zobrazuj=20jen=20zadan=C3=A1=20a=20ve=C5=99ejn?= =?UTF-8?q?=C3=A1=20t=C3=A9mata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/views.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/seminar/views.py b/seminar/views.py index d8616a8d..46dc0c1d 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -15,17 +15,22 @@ from datetime import timedelta, date, datetime from itertools import groupby +def verejna_temata(rocnik): + """Vrací queryset zveřejněných témat v daném ročníku. + """ + return Problem.objects.filter(typ=Problem.TYP_TEMA, cislo_zadani__rocnik=rocnik, cislo_zadani__verejne_db=True).order_by('kod') + + def AktualniZadaniView(request): nastaveni = get_object_or_404(Nastaveni) problemy = Problem.objects.filter(cislo_zadani=nastaveni.aktualni_cislo).filter(stav = 'zadany') ulohy = problemy.filter(typ = 'uloha').order_by('kod') serialy = problemy.filter(typ = 'serial').order_by('kod') - temata = problemy.filter(typ = 'tema').order_by('kod') jednorazove_problemy = [ulohy, serialy] return render(request, 'seminar/zadani/AktualniZadani.html', {'nastaveni': nastaveni, 'jednorazove_problemy': jednorazove_problemy, - 'temata': temata, + 'temata': verejna_temata(nastaveni.aktualni_rocnik), }, ) @@ -33,7 +38,7 @@ def ZadaniTemataView(request): nastaveni = get_object_or_404(Nastaveni) return render(request, 'seminar/zadani/Temata.html', { - 'temata': Problem.objects.filter(typ=Problem.TYP_TEMA, stav=Problem.STAV_ZADANY, cislo_zadani__rocnik=nastaveni.aktualni_rocnik).order_by('kod'), + 'temata': verejna_temata(nastaveni.aktualni_rocnik) } ) @@ -190,8 +195,7 @@ class RocnikView(generic.DetailView): context = super(RocnikView, self).get_context_data(**kwargs) context['vysledkovka'] = vysledkovka_rocniku(context["rocnik"]) - temata_v_rocniku = Problem.objects.filter(typ=Problem.TYP_TEMA, cislo_zadani__rocnik=context['rocnik']).order_by('kod') - context['temata_v_rocniku'] = temata_v_rocniku + context['temata_v_rocniku'] = verejna_temata(context["rocnik"]) return context