Submitovatko: opravena reakce u nevalidnich formularu, bugfix
This commit is contained in:
parent
fe5cf93ed8
commit
f147318df5
1 changed files with 6 additions and 5 deletions
|
@ -1161,6 +1161,7 @@ class SubmitSolutionView(LoginRequiredMixin, CreateView):
|
||||||
model = s.Reseni
|
model = s.Reseni
|
||||||
template_name = 'seminar/nahraj_reseni.html'
|
template_name = 'seminar/nahraj_reseni.html'
|
||||||
form_class = f.NahrajReseniForm
|
form_class = f.NahrajReseniForm
|
||||||
|
success_url = '/'
|
||||||
|
|
||||||
def get_context_data(self,**kwargs):
|
def get_context_data(self,**kwargs):
|
||||||
data = super().get_context_data(**kwargs)
|
data = super().get_context_data(**kwargs)
|
||||||
|
@ -1175,17 +1176,17 @@ class SubmitSolutionView(LoginRequiredMixin, CreateView):
|
||||||
def form_valid(self,form):
|
def form_valid(self,form):
|
||||||
context = self.get_context_data()
|
context = self.get_context_data()
|
||||||
prilohy = context['prilohy']
|
prilohy = context['prilohy']
|
||||||
|
if not prilohy.is_valid():
|
||||||
|
return super().form_invalid(form)
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
self.object = form.save()
|
self.object = form.save()
|
||||||
self.object.resitele.add(Resitel.objects.get(osoba__user = self.request.user))
|
self.object.resitele.add(Resitel.objects.get(osoba__user = self.request.user))
|
||||||
self.object.cas_doruceni = timezone.now()
|
self.object.cas_doruceni = timezone.now()
|
||||||
self.object.forma = s.Reseni.FORMA_UPLOAD
|
self.object.forma = s.Reseni.FORMA_UPLOAD
|
||||||
self.object.save()
|
self.object.save()
|
||||||
if prilohy.is_valid():
|
|
||||||
prilohy.instance = self.object
|
prilohy.instance = self.object
|
||||||
prilohy.save()
|
prilohy.save()
|
||||||
else:
|
|
||||||
raise Exception("Uploadovane soubory nebyly validni")
|
|
||||||
|
|
||||||
return HttpResponseRedirect(self.get_success_url())
|
return HttpResponseRedirect(self.get_success_url())
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue