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