Browse Source

Submitovatko: opravena reakce u nevalidnich formularu, bugfix

export_seznamu_prednasek
parent
commit
f147318df5
  1. 11
      seminar/views.py

11
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())

Loading…
Cancel
Save