|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from django.forms import ModelForm, Textarea
|
|
|
|
from .models import OdpovedUcastnika, SpravnaOdpoved, NapovezenoUcastnikovi, Napoveda
|
|
|
|
|
|
|
|
|
|
|
|
class SifrovackaForm(ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = OdpovedUcastnika
|
|
|
|
fields = ["sifra", "odpoved", ]
|
|
|
|
widgets = {
|
|
|
|
"odpoved": Textarea(attrs={'rows': 1, 'cols': 30}),
|
|
|
|
}
|
|
|
|
|
|
|
|
def clean_sifra(self):
|
|
|
|
sifra = self.cleaned_data.get('sifra')
|
|
|
|
if SpravnaOdpoved.objects.filter(sifra=sifra).count() == 0:
|
|
|
|
raise ValidationError("Tohle číslo šifry v databázi nemáme. Zkontrolujte si ho prosím.")
|
|
|
|
return sifra
|
|
|
|
|
|
|
|
|
|
|
|
class NapovedaForm(ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = NapovezenoUcastnikovi
|
|
|
|
fields = ["sifra",]
|
|
|
|
|
|
|
|
def clean_sifra(self):
|
|
|
|
sifra = self.cleaned_data.get('sifra')
|
|
|
|
if Napoveda.objects.filter(sifra=sifra).count() == 0:
|
|
|
|
raise ValidationError("K tomuto číslu šifry nemáme nápovědu. Zkontrolujte si ho prosím.")
|
|
|
|
return sifra
|