Browse Source

Submitovatko: opravena reakce u nevalidnich formularu, bugfix

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

7
seminar/views.py

@ -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…
Cancel
Save