|
@ -4,14 +4,18 @@ from django.views.generic.base import View |
|
|
from django.views.generic.detail import SingleObjectMixin |
|
|
from django.views.generic.detail import SingleObjectMixin |
|
|
from django.shortcuts import redirect, get_object_or_404 |
|
|
from django.shortcuts import redirect, get_object_or_404 |
|
|
from django.urls import reverse |
|
|
from django.urls import reverse |
|
|
|
|
|
from django.db import transaction |
|
|
|
|
|
|
|
|
from dataclasses import dataclass |
|
|
from dataclasses import dataclass |
|
|
import datetime |
|
|
import datetime |
|
|
|
|
|
import logging |
|
|
|
|
|
|
|
|
import seminar.models as m |
|
|
import seminar.models as m |
|
|
import seminar.forms as f |
|
|
import seminar.forms as f |
|
|
from seminar.utils import aktivniResitele, resi_v_rocniku |
|
|
from seminar.utils import aktivniResitele, resi_v_rocniku |
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
# Co chceme? |
|
|
# Co chceme? |
|
|
# - "Tabulku" aktuální řešitelé x zveřejněné problémy, v buňkách počet řešení |
|
|
# - "Tabulku" aktuální řešitelé x zveřejněné problémy, v buňkách počet řešení |
|
|
# - TabulkaOdevzdanychReseniView |
|
|
# - TabulkaOdevzdanychReseniView |
|
@ -153,17 +157,35 @@ class DetailReseniView(DetailView): |
|
|
return ctx |
|
|
return ctx |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HodnoceniReseniView(SingleObjectMixin, FormView): |
|
|
def hodnoceniReseniView(request, pk, *args, **kwargs): |
|
|
model = m.Reseni |
|
|
reseni = get_object_or_404(m.Reseni, pk=pk) |
|
|
template_name = 'seminar/odevzdavatko/detail.html' |
|
|
template_name = 'seminar/odevzdavatko/detail.html' |
|
|
form_class = f.OhodnoceniReseniFormSet |
|
|
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): |
|
|
return redirect(success_url) |
|
|
# 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): |
|
|
|
|
|
... |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Přehled všech řešení kvůli debugování |
|
|
# Přehled všech řešení kvůli debugování |
|
|