You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.1 KiB

from django.urls import reverse
from django.views.generic import FormView, ListView
from seminar.views import formularOKView
from .forms import SifrovackaForm
from .models import OdpovedUcastnika, SpravnaOdpoved
from seminar.models.personalni import Resitel
# Create your views here.
class SifrovackaView(FormView):
template_name = 'sifrovacka/sifrovacka.html'
form_class = SifrovackaForm
def form_valid(self, form):
instance = form.save(commit=False)
resitel = Resitel.objects.get(osoba__user=self.request.user)
instance.resitel = resitel
instance.save()
sifra = SpravnaOdpoved.objects.filter(sifra=instance.sifra, odpoved__iexact=instance.odpoved.strip()).first()
if sifra is None:
return formularOKView(self.request, f'<h2>Bohužel vám hvězdy nebyly nakloněny. Rozumějte <i>máte to blbě</i>.</h2> <p><a href="{reverse("sifrovacka")}">Zkusit znovu.</a></p><br><br><br>')
return formularOKView(self.request, f'<h2>{sifra.skryty_text}</h2> <p><a href="{reverse("sifrovacka")}">Odevzdat další.</a></p><br><br><br>')
class SifrovackaListView(ListView):
template_name = 'sifrovacka/odpovedi_list.html'
model = OdpovedUcastnika