2021-11-07 10:25:34 +01:00
|
|
|
from django.shortcuts import get_object_or_404, render
|
2021-10-08 10:36:59 +02:00
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
2015-03-13 20:08:18 +01:00
|
|
|
from django.views import generic
|
2021-10-08 18:06:02 +02:00
|
|
|
from django.views.generic.base import RedirectView
|
2023-08-10 15:21:22 +02:00
|
|
|
|
|
|
|
from tvorba.models import Rocnik, Deadline, Tema
|
|
|
|
from seminar.models import *
|
|
|
|
from personalni.models import Organizator
|
|
|
|
|
|
|
|
from vysledkovky.utils import VysledkovkaRocniku
|
|
|
|
|
2019-08-14 14:29:24 +02:00
|
|
|
from django.utils import timezone
|
2016-02-17 16:17:11 +01:00
|
|
|
|
2015-09-03 22:09:35 +02:00
|
|
|
|
2020-07-15 11:21:16 +02:00
|
|
|
# ze starého modelu
|
|
|
|
#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 temata_v_rocniku(rocnik):
|
|
|
|
# return Problem.objects.filter(typ=Problem.TYP_TEMA, rocnik=rocnik)
|
2021-09-04 22:07:13 +02:00
|
|
|
|
2020-04-23 00:41:04 +02:00
|
|
|
|
2019-12-05 00:50:04 +01:00
|
|
|
|
2021-02-09 21:43:07 +01:00
|
|
|
#class AktualniZadaniView(generic.TemplateView):
|
|
|
|
# template_name = 'seminar/treenode.html'
|
2020-10-21 08:41:20 +02:00
|
|
|
|
|
|
|
# TODO Co chceme vlastně zobrazovat na této stránce? Zatím je zde aktuální číslo, ale může tu být cokoli jiného...
|
|
|
|
#class AktualniZadaniView(TreeNodeView):
|
|
|
|
# def get_object(self):
|
|
|
|
# nastaveni = get_object_or_404(Nastaveni)
|
|
|
|
# return nastaveni.aktualni_cislo.cislonode
|
|
|
|
#
|
|
|
|
# def get_context_data(self,**kwargs):
|
|
|
|
# nastaveni = get_object_or_404(Nastaveni)
|
|
|
|
# context = super().get_context_data(**kwargs)
|
|
|
|
# verejne = nastaveni.aktualni_cislo.verejne()
|
2023-08-10 15:34:32 +02:00
|
|
|
# context['verejne'] = verejne
|
2020-10-21 08:41:20 +02:00
|
|
|
# return context
|
2020-03-19 00:50:39 +01:00
|
|
|
|
2021-02-09 21:43:07 +01:00
|
|
|
def AktualniZadaniView(request):
|
|
|
|
nastaveni = get_object_or_404(Nastaveni)
|
|
|
|
verejne = nastaveni.aktualni_cislo.verejne()
|
|
|
|
return render(request, 'seminar/zadani/AktualniZadani.html',
|
|
|
|
{'nastaveni': nastaveni,
|
|
|
|
'verejne': verejne,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2020-10-27 23:28:23 +01:00
|
|
|
def ZadaniTemataView(request):
|
2020-12-01 23:52:03 +01:00
|
|
|
nastaveni = get_object_or_404(Nastaveni)
|
|
|
|
verejne = nastaveni.aktualni_cislo.verejne()
|
|
|
|
akt_rocnik = nastaveni.aktualni_cislo.rocnik
|
2023-07-31 19:13:56 +02:00
|
|
|
temata = Tema.objects.filter(rocnik=akt_rocnik, stav='zadany')
|
2020-12-01 23:52:03 +01:00
|
|
|
return render(request, 'seminar/tematka/rozcestnik.html',
|
|
|
|
{
|
|
|
|
'tematka': temata,
|
|
|
|
'verejne': verejne,
|
|
|
|
},
|
|
|
|
)
|
2020-10-27 23:28:23 +01:00
|
|
|
|
|
|
|
|
2020-03-19 00:50:39 +01:00
|
|
|
# nastaveni = get_object_or_404(Nastaveni)
|
|
|
|
# temata = verejna_temata(nastaveni.aktualni_rocnik)
|
|
|
|
# for t in temata:
|
|
|
|
# if request.user.is_staff:
|
|
|
|
# t.prispevky = t.prispevek_set.filter(problem=t)
|
|
|
|
# else:
|
|
|
|
# t.prispevky = t.prispevek_set.filter(problem=t, zverejnit=True)
|
|
|
|
# return render(request, 'seminar/zadani/Temata.html',
|
|
|
|
# {
|
|
|
|
# 'temata': temata,
|
|
|
|
# }
|
|
|
|
# )
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#def TemataRozcestnikView(request):
|
|
|
|
# print("=============================================")
|
2023-07-31 19:13:56 +02:00
|
|
|
# nastaveni = Nastaveni.objects.first()
|
|
|
|
# tematka_objects = Tema.objects.filter(rocnik=nastaveni.aktualni_rocnik())
|
2020-03-19 00:50:39 +01:00
|
|
|
# tematka = [] #List tematka obsahuje pro kazde tematko object a list vsech TemaVCisleNodu - implementované pomocí slovníku
|
|
|
|
# for tematko_object in tematka_objects:
|
|
|
|
# print("AKTUALNI TEMATKO")
|
|
|
|
# print(tematko_object.id)
|
|
|
|
# odkazy = vytahniZLesaSeznam(tematko_object, nastaveni.aktualni_rocnik().rocniknode, pouze_zajimave = True) #Odkazy jsou tuply (node, depth) v listu
|
|
|
|
# print(odkazy)
|
|
|
|
# cisla = [] # List tuplů (nazev cisla, list odkazů)
|
|
|
|
# vcisle = []
|
|
|
|
# cislo = None
|
|
|
|
# for odkaz in odkazy:
|
|
|
|
# if odkaz[1] == 0:
|
|
|
|
# if cislo != None:
|
|
|
|
# cisla.append((cislo, vcisle))
|
|
|
|
# cislo = (odkaz[0].getOdkazStr(), odkaz[0].getOdkaz())
|
|
|
|
# vcisle = []
|
|
|
|
# else:
|
|
|
|
# print(odkaz[0].getOdkaz())
|
|
|
|
# vcisle.append((odkaz[0].getOdkazStr(), odkaz[0].getOdkaz()))
|
|
|
|
# if cislo != None:
|
|
|
|
# cisla.append((cislo, vcisle))
|
|
|
|
#
|
|
|
|
# print(cisla)
|
|
|
|
# tematka.append({
|
|
|
|
# "kod" : tematko_object.kod,
|
|
|
|
# "nazev" : tematko_object.nazev,
|
|
|
|
# "abstrakt" : tematko_object.abstrakt,
|
|
|
|
# "obrazek": tematko_object.obrazek,
|
|
|
|
# "cisla" : cisla
|
|
|
|
# })
|
|
|
|
# return render(request, 'seminar/tematka/rozcestnik.html', {"tematka": tematka, "rocnik" : nastaveni.aktualni_rocnik().rocnik})
|
2020-09-01 23:04:19 +02:00
|
|
|
#
|
2016-07-24 23:16:06 +02:00
|
|
|
|
2021-03-02 21:49:12 +01:00
|
|
|
def ZadaniAktualniVysledkovkaView(request):
|
|
|
|
nastaveni = get_object_or_404(Nastaveni)
|
|
|
|
# Aktualni verejna vysledkovka
|
2021-09-06 15:25:54 +02:00
|
|
|
rocnik = nastaveni.aktualni_rocnik
|
2022-10-01 21:47:15 +02:00
|
|
|
context = {'vysledkovka': VysledkovkaRocniku(rocnik, True)}
|
2021-10-07 19:30:28 +02:00
|
|
|
|
2021-03-02 21:49:12 +01:00
|
|
|
# kdyz neni verejna vysledkovka, tak zobraz starou
|
2022-10-01 21:47:15 +02:00
|
|
|
if len(context['vysledkovka'].cisla_rocniku) == 0:
|
2021-03-02 21:49:12 +01:00
|
|
|
try:
|
|
|
|
minuly_rocnik = Rocnik.objects.get(
|
2022-10-01 21:47:15 +02:00
|
|
|
rocnik=(rocnik.rocnik-1))
|
2021-09-06 15:25:54 +02:00
|
|
|
rocnik = minuly_rocnik
|
2021-10-07 19:30:28 +02:00
|
|
|
|
|
|
|
# Přepíšeme prázdnou výsledkovku výsledkovkou z minulého ročníku
|
2022-10-01 21:47:15 +02:00
|
|
|
context['vysledkovka'] = VysledkovkaRocniku(rocnik, True)
|
2021-03-02 21:49:12 +01:00
|
|
|
except ObjectDoesNotExist:
|
|
|
|
pass
|
2021-10-07 19:30:28 +02:00
|
|
|
|
|
|
|
context['rocnik'] = rocnik
|
2021-03-02 21:49:12 +01:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
'seminar/zadani/AktualniVysledkovka.html',
|
2021-10-07 19:30:28 +02:00
|
|
|
context
|
2021-03-02 21:49:12 +01:00
|
|
|
)
|
2015-09-23 17:28:14 +02:00
|
|
|
|
|
|
|
|
2015-09-03 22:09:35 +02:00
|
|
|
### Titulni strana
|
|
|
|
|
2020-06-26 02:12:01 +02:00
|
|
|
def spravne_novinky(request):
|
|
|
|
"""
|
|
|
|
Vrátí správný QuerySet novinek, tedy ten, který daný uživatel smí vidět.
|
|
|
|
Tj. Organizátorům všechny, ostatním jen veřejné
|
|
|
|
"""
|
|
|
|
user = request.user
|
|
|
|
# Využíváme líné vyhodnocování QuerySetů
|
|
|
|
qs = Novinky.objects.all()
|
2021-02-24 00:54:39 +01:00
|
|
|
if not user.je_org:
|
2020-06-26 02:12:01 +02:00
|
|
|
qs = qs.filter(zverejneno=True)
|
|
|
|
return qs.order_by('-datum')
|
|
|
|
|
2020-07-15 11:21:16 +02:00
|
|
|
def aktualni_temata(rocnik):
|
|
|
|
"""
|
|
|
|
Vrací PolymorphicQuerySet témat v daném ročníku, ke kterým se aktuálně dá něco odevzdat.
|
|
|
|
"""
|
|
|
|
return Tema.objects.filter(rocnik=rocnik, stav='zadany').order_by('kod')
|
|
|
|
|
2020-06-26 02:12:01 +02:00
|
|
|
|
2015-09-03 22:09:35 +02:00
|
|
|
class TitulniStranaView(generic.ListView):
|
2022-09-28 09:51:19 +02:00
|
|
|
template_name= 'seminar/titulnistrana/titulnistrana.html'
|
2020-06-26 01:37:58 +02:00
|
|
|
|
|
|
|
def get_queryset(self):
|
2020-07-15 21:12:00 +02:00
|
|
|
return spravne_novinky(self.request)[:3]
|
2019-05-11 01:15:05 +02:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(TitulniStranaView, self).get_context_data(**kwargs)
|
|
|
|
nastaveni = get_object_or_404(Nastaveni)
|
2021-09-02 19:35:21 +02:00
|
|
|
|
2023-07-31 19:13:56 +02:00
|
|
|
deadline = Deadline.objects.filter(deadline__gte=timezone.now()).order_by("deadline").first()
|
2022-10-09 09:52:46 +02:00
|
|
|
context['nejblizsi_deadline'] = deadline
|
2020-07-14 23:21:55 +02:00
|
|
|
|
|
|
|
# Aktuální témata
|
2020-07-15 11:21:16 +02:00
|
|
|
nazvy_a_odkazy_na_aktualni_temata = []
|
|
|
|
akt_temata = aktualni_temata(nastaveni.aktualni_rocnik)
|
|
|
|
|
|
|
|
for tema in akt_temata:
|
|
|
|
# FIXME: netuším, jestli funguje tema.verejne_url(), nemáme testdata na témátka - je to asi url vzhledem k ročníku
|
|
|
|
nazvy_a_odkazy_na_aktualni_temata.append({'nazev':tema.nazev,'url':tema.verejne_url()})
|
|
|
|
|
|
|
|
context['aktualni_temata'] = nazvy_a_odkazy_na_aktualni_temata
|
|
|
|
|
|
|
|
print(context)
|
2020-07-14 23:21:55 +02:00
|
|
|
|
2019-05-11 01:15:05 +02:00
|
|
|
return context
|
2015-09-07 17:00:19 +02:00
|
|
|
|
2015-09-12 00:22:17 +02:00
|
|
|
class StareNovinkyView(generic.ListView):
|
2019-05-11 01:15:05 +02:00
|
|
|
template_name = 'seminar/stare_novinky.html'
|
2020-06-26 02:12:01 +02:00
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
return spravne_novinky(self.request)
|
2015-09-12 00:22:17 +02:00
|
|
|
|
2015-06-29 17:51:18 +02:00
|
|
|
### Co je M&M
|
2015-06-03 14:16:30 +02:00
|
|
|
|
2017-01-20 12:13:25 +01:00
|
|
|
|
|
|
|
# Organizatori
|
2019-08-14 14:29:24 +02:00
|
|
|
def aktivniOrganizatori(datum=timezone.now()):
|
2019-05-11 01:15:05 +02:00
|
|
|
return Organizator.objects.exclude(
|
|
|
|
organizuje_do__isnull=False,
|
|
|
|
organizuje_do__lt=datum
|
2019-07-25 21:20:15 +02:00
|
|
|
).order_by('osoba__jmeno')
|
2017-01-20 12:13:25 +01:00
|
|
|
|
2015-08-23 15:06:47 +02:00
|
|
|
|
2015-06-28 22:07:27 +02:00
|
|
|
class CojemamOrganizatoriView(generic.ListView):
|
2019-05-11 01:15:05 +02:00
|
|
|
model = Organizator
|
|
|
|
template_name = 'seminar/cojemam/organizatori.html'
|
|
|
|
queryset = aktivniOrganizatori()
|
2017-01-20 12:13:25 +01:00
|
|
|
|
2019-05-11 01:15:05 +02:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(CojemamOrganizatoriView, self).get_context_data(**kwargs)
|
|
|
|
context['aktivni'] = True
|
|
|
|
return context
|
2015-08-23 15:06:47 +02:00
|
|
|
|
2017-01-20 12:13:25 +01:00
|
|
|
|
2015-08-23 15:06:47 +02:00
|
|
|
class CojemamOrganizatoriStariView(generic.ListView):
|
2019-05-11 01:15:05 +02:00
|
|
|
model = Organizator
|
|
|
|
template_name = 'seminar/cojemam/organizatori.html'
|
|
|
|
queryset = Organizator.objects.exclude(
|
|
|
|
id__in=aktivniOrganizatori()).order_by('-organizuje_do')
|
2015-06-03 14:16:30 +02:00
|
|
|
|
2015-09-13 15:31:34 +02:00
|
|
|
|
2020-09-21 13:19:07 +02:00
|
|
|
#------------------ Jak řešit - možná má být udělané úplně jinak
|
2021-09-02 19:35:21 +02:00
|
|
|
|
2020-09-21 13:19:07 +02:00
|
|
|
class JakResitView(generic.ListView):
|
2022-09-28 09:51:19 +02:00
|
|
|
template_name = 'seminar/jakresit/jak-resit.html'
|
2021-09-02 19:35:21 +02:00
|
|
|
|
2020-09-21 13:19:07 +02:00
|
|
|
def get_queryset(self):
|
2020-10-13 23:25:39 +02:00
|
|
|
return None
|
2021-04-28 21:26:30 +02:00
|
|
|
|
|
|
|
class AktualniRocnikRedirectView(RedirectView):
|
|
|
|
permanent=False
|
|
|
|
pattern_name = 'seminar_rocnik'
|
|
|
|
|
|
|
|
def get_redirect_url(self, *args, **kwargs):
|
2023-07-31 19:13:56 +02:00
|
|
|
aktualni_rocnik = Nastaveni.get_solo().aktualni_rocnik.rocnik
|
2021-04-28 21:26:30 +02:00
|
|
|
return super().get_redirect_url(rocnik=aktualni_rocnik, *args, **kwargs)
|