|
|
@ -218,10 +218,11 @@ class DetailReseniView(DetailView): |
|
|
|
self.reseni = get_object_or_404(m.Reseni, id=self.kwargs['pk']) |
|
|
|
result = [] # Slovníky s klíči problem, body, deadline_body -- initial data pro f.OhodnoceniReseniFormSet |
|
|
|
for hodn in m.Hodnoceni.objects.filter(reseni=self.reseni): |
|
|
|
result.append( |
|
|
|
{"problem": hodn.problem, |
|
|
|
result.append({ |
|
|
|
"problem": hodn.problem, |
|
|
|
"body": hodn.body, |
|
|
|
"deadline_body": hodn.deadline_body, |
|
|
|
"feedback": hodn.feedback, |
|
|
|
}) |
|
|
|
return result |
|
|
|
|
|
|
@ -245,30 +246,26 @@ def hodnoceniReseniView(request, pk, *args, **kwargs): |
|
|
|
formset = f.OhodnoceniReseniFormSet(request.POST) |
|
|
|
poznamka_form = f.PoznamkaReseniForm(request.POST, instance=reseni) |
|
|
|
# TODO: Napsat validaci formuláře a formsetu |
|
|
|
# TODO: Implementovat větev, kdy formulář validní není. |
|
|
|
if formset.is_valid() and poznamka_form.is_valid(): |
|
|
|
with transaction.atomic(): |
|
|
|
# Poznámka je jednoduchá na zpracování: |
|
|
|
poznamka_form.save() |
|
|
|
if not (formset.is_valid() and poznamka_form.is_valid()): |
|
|
|
raise ValueError(formset.errors, poznamka_form.errors) |
|
|
|
|
|
|
|
# Smažeme všechna dosavadní hodnocení tohoto řešení |
|
|
|
qs = m.Hodnoceni.objects.filter(reseni=reseni) |
|
|
|
logger.info(f"Will delete {qs.count()} objects: {qs}") |
|
|
|
qs.delete() |
|
|
|
|
|
|
|
# Vyrobíme nová podle formsetu |
|
|
|
for form in formset: |
|
|
|
problem = form.cleaned_data['problem'] |
|
|
|
body = form.cleaned_data['body'] |
|
|
|
deadline_body = form.cleaned_data['deadline_body'] |
|
|
|
hodnoceni = m.Hodnoceni( |
|
|
|
problem=problem, |
|
|
|
body=body, |
|
|
|
deadline_body=deadline_body, |
|
|
|
with transaction.atomic(): |
|
|
|
# Poznámka je jednoduchá na zpracování: |
|
|
|
poznamka_form.save() |
|
|
|
|
|
|
|
# Smažeme všechna dosavadní hodnocení tohoto řešení |
|
|
|
qs = m.Hodnoceni.objects.filter(reseni=reseni) |
|
|
|
logger.info(f"Will delete {qs.count()} objects: {qs}") |
|
|
|
qs.delete() |
|
|
|
|
|
|
|
# Vyrobíme nová podle formsetu |
|
|
|
for form in formset: |
|
|
|
hodnoceni = m.Hodnoceni( |
|
|
|
reseni=reseni, |
|
|
|
**form.cleaned_data, |
|
|
|
) |
|
|
|
logger.info(f"Creating Hodnoceni: {hodnoceni}") |
|
|
|
hodnoceni.save() |
|
|
|
logger.info(f"Creating Hodnoceni: {hodnoceni}") |
|
|
|
hodnoceni.save() |
|
|
|
|
|
|
|
return redirect(success_url) |
|
|
|
|
|
|
@ -285,6 +282,7 @@ class ResitelReseniView(DetailView): |
|
|
|
{ |
|
|
|
"problem": hodn.problem, |
|
|
|
"body": hodn.body, |
|
|
|
"feedback": hodn.feedback, |
|
|
|
# "deadline_body": hodn.deadline_body, |
|
|
|
} |
|
|
|
) |
|
|
|