|
|
@ -206,9 +206,9 @@ class DetailReseniView(DetailView): |
|
|
|
template_name = 'seminar/odevzdavatko/detail.html' |
|
|
|
|
|
|
|
def aktualni_hodnoceni(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, cislo_body -- initial data pro f.OhodnoceniReseniFormSet |
|
|
|
for hodn in m.Hodnoceni.objects.filter(reseni=reseni): |
|
|
|
for hodn in m.Hodnoceni.objects.filter(reseni=self.reseni): |
|
|
|
result.append( |
|
|
|
{"problem": hodn.problem, |
|
|
|
"body": hodn.body, |
|
|
@ -221,6 +221,7 @@ class DetailReseniView(DetailView): |
|
|
|
ctx['form'] = f.OhodnoceniReseniFormSet( |
|
|
|
initial = self.aktualni_hodnoceni() |
|
|
|
) |
|
|
|
ctx['poznamka_form'] = f.PoznamkaReseniForm(instance=self.reseni) |
|
|
|
return ctx |
|
|
|
|
|
|
|
|
|
|
@ -233,10 +234,14 @@ def hodnoceniReseniView(request, pk, *args, **kwargs): |
|
|
|
# FIXME: Použit initial i tady a nebastlit hodnocení tak nízkoúrovňově |
|
|
|
# Also: https://docs.djangoproject.com/en/2.2/topics/forms/modelforms/#django.forms.ModelForm |
|
|
|
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(): |
|
|
|
if formset.is_valid() and poznamka_form.is_valid(): |
|
|
|
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}") |
|
|
|