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
|
||||
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…
Reference in a new issue