Web M&M
https://mam.matfyz.cz
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.
54 lines
2.0 KiB
54 lines
2.0 KiB
from django.urls import reverse
|
|
from django.views.generic import FormView, ListView
|
|
|
|
from seminar.views import formularOKView
|
|
from .forms import SifrovackaForm, NapovedaForm
|
|
from .models import OdpovedUcastnika, SpravnaOdpoved, Napoveda, NapovezenoUcastnikovi
|
|
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'<h1>Bohužel vám hvězdy nebyly nakloněny. Rozumějte <i>máte to blbě</i>.</h1> <p><a href="{reverse("sifrovacka")}">Zkusit znovu.</a></p><br><br><br>')
|
|
|
|
instance.uspech = True
|
|
instance.save()
|
|
|
|
return formularOKView(self.request, f'<h1>{sifra.skryty_text}</h1> <p><a href="{reverse("sifrovacka")}">Odevzdat další.</a></p><br><br><br>')
|
|
|
|
|
|
class SifrovackaListView(ListView):
|
|
template_name = 'sifrovacka/odpovedi_list.html'
|
|
model = OdpovedUcastnika
|
|
|
|
|
|
class NapovedaView(FormView):
|
|
template_name = 'sifrovacka/napoveda.html'
|
|
form_class = NapovedaForm
|
|
|
|
def form_valid(self, form):
|
|
instance = form.save(commit=False)
|
|
resitel = Resitel.objects.get(osoba__user=self.request.user)
|
|
instance.resitel = resitel
|
|
|
|
if NapovezenoUcastnikovi.objects.filter(resitel=resitel, sifra=instance.sifra).first() is None:
|
|
instance.save()
|
|
|
|
napoveda = Napoveda.objects.filter(sifra=instance.sifra).first()
|
|
return formularOKView(self.request, f'<h1>Nápověda k šifře číslo {instance.sifra} je:</h1><p>{napoveda.text}</p> <p><a href="{reverse("sifrovacka")}">Odevzdat řešení.</a></p><br><br><br>')
|
|
|
|
|
|
class NapovedaListView(ListView):
|
|
template_name = 'sifrovacka/napovedy_list.html'
|
|
model = NapovezenoUcastnikovi
|
|
|