From 512f14ed4da890bf97ac855276985cb7a36997aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Mon, 22 May 2023 22:24:14 +0200 Subject: [PATCH] =?UTF-8?q?Odevzd=C3=A1v=C3=A1tko:=20Nezadan=C3=A9=20probl?= =?UTF-8?q?=C3=A9my=20nelze=20odevzdat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- odevzdavatko/forms.py | 7 +++++++ .../templates/odevzdavatko/nahraj_reseni.html | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/odevzdavatko/forms.py b/odevzdavatko/forms.py index 6e1898eb..ba5d3153 100644 --- a/odevzdavatko/forms.py +++ b/odevzdavatko/forms.py @@ -89,6 +89,13 @@ class NahrajReseniForm(forms.ModelForm): if 'problem' in self.fields: self.fields['problem'].label = "Všechny řešené problémy" + def clean_problem(self): + problem = self.cleaned_data.get('problem') + for p in problem: + if p.stav != m.Problem.STAV_ZADANY: + raise forms.ValidationError("Problém " + str(p) + " již nelze řešit!") + return problem + ReseniSPrilohamiFormSet = inlineformset_factory(m.Reseni,m.PrilohaReseni, form = NahrajReseniForm, fields = ('soubor','res_poznamka'), diff --git a/odevzdavatko/templates/odevzdavatko/nahraj_reseni.html b/odevzdavatko/templates/odevzdavatko/nahraj_reseni.html index e82fa1cd..19101b6b 100644 --- a/odevzdavatko/templates/odevzdavatko/nahraj_reseni.html +++ b/odevzdavatko/templates/odevzdavatko/nahraj_reseni.html @@ -30,6 +30,13 @@ {{ field }} + + {% if field.errors %} + + {{ field.errors }} + + {% endif %} + {% endwith %} @@ -54,6 +61,13 @@ {{ field }} + + {% if field.errors %} + + {{ field.errors }} + + {% endif %} + {% endwith %} @@ -61,6 +75,8 @@ {% include "odevzdavatko/prilohy.html" %} +{{form.non_field_errors}} +

Odevzdat řešení