|
|
@ -4,14 +4,18 @@ from django.views.generic.base import View |
|
|
|
from django.views.generic.detail import SingleObjectMixin |
|
|
|
from django.shortcuts import redirect, get_object_or_404 |
|
|
|
from django.urls import reverse |
|
|
|
from django.db import transaction |
|
|
|
|
|
|
|
from dataclasses import dataclass |
|
|
|
import datetime |
|
|
|
import logging |
|
|
|
|
|
|
|
import seminar.models as m |
|
|
|
import seminar.forms as f |
|
|
|
from seminar.utils import aktivniResitele, resi_v_rocniku |
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
# Co chceme? |
|
|
|
# - "Tabulku" aktuální řešitelé x zveřejněné problémy, v buňkách počet řešení |
|
|
|
# - TabulkaOdevzdanychReseniView |
|
|
@ -153,17 +157,35 @@ class DetailReseniView(DetailView): |
|
|
|
return ctx |
|
|
|
|
|
|
|
|
|
|
|
class HodnoceniReseniView(SingleObjectMixin, FormView): |
|
|
|
model = m.Reseni |
|
|
|
def hodnoceniReseniView(request, pk, *args, **kwargs): |
|
|
|
reseni = get_object_or_404(m.Reseni, pk=pk) |
|
|
|
template_name = 'seminar/odevzdavatko/detail.html' |
|
|
|
form_class = f.OhodnoceniReseniFormSet |
|
|
|
success_url = reverse('odevzdavatko_detail_reseni', kwargs={'pk': pk}) |
|
|
|
|
|
|
|
formset = f.OhodnoceniReseniFormSet(request.POST) |
|
|
|
if formset.is_valid(): |
|
|
|
with transaction.atomic(): |
|
|
|
# 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'] |
|
|
|
cislo_body = form.cleaned_data['cislo_body'] |
|
|
|
hodnoceni = m.Hodnoceni( |
|
|
|
problem=problem, |
|
|
|
body=body, |
|
|
|
cislo_body=cislo_body, |
|
|
|
reseni=reseni, |
|
|
|
) |
|
|
|
logger.info(f"Creating Hodnoceni: {hodnoceni}") |
|
|
|
hodnoceni.save() |
|
|
|
|
|
|
|
def get_success_url(self): |
|
|
|
# Funkce to je jen proto, aby se dalo použít self. |
|
|
|
return reverse('odevzdavatko_detail_reseni', kwargs={'pk': self.kwargs['pk']}) |
|
|
|
|
|
|
|
def form_vaild(self, form): |
|
|
|
... |
|
|
|
return redirect(success_url) |
|
|
|
|
|
|
|
|
|
|
|
# Přehled všech řešení kvůli debugování |
|
|
|