From f147318df575494d0bf38b82d156a89641579f88 Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Sat, 29 Feb 2020 18:05:49 +0100 Subject: [PATCH] Submitovatko: opravena reakce u nevalidnich formularu, bugfix --- seminar/views.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/seminar/views.py b/seminar/views.py index b1bacc48..36320ba3 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -1161,6 +1161,7 @@ class SubmitSolutionView(LoginRequiredMixin, CreateView): model = s.Reseni template_name = 'seminar/nahraj_reseni.html' form_class = f.NahrajReseniForm + success_url = '/' def get_context_data(self,**kwargs): data = super().get_context_data(**kwargs) @@ -1175,17 +1176,17 @@ class SubmitSolutionView(LoginRequiredMixin, CreateView): def form_valid(self,form): context = self.get_context_data() prilohy = context['prilohy'] + if not prilohy.is_valid(): + return super().form_invalid(form) with transaction.atomic(): self.object = form.save() self.object.resitele.add(Resitel.objects.get(osoba__user = self.request.user)) self.object.cas_doruceni = timezone.now() self.object.forma = s.Reseni.FORMA_UPLOAD self.object.save() - if prilohy.is_valid(): - prilohy.instance = self.object - prilohy.save() - else: - raise Exception("Uploadovane soubory nebyly validni") + + prilohy.instance = self.object + prilohy.save() return HttpResponseRedirect(self.get_success_url())