Implementováno zadávání bodů
This commit is contained in:
parent
64d3701d0f
commit
631bcd5bdb
2 changed files with 30 additions and 8 deletions
|
@ -169,7 +169,7 @@ urlpatterns = [
|
||||||
|
|
||||||
path('temp/reseni/', org_required(views.TabulkaOdevzdanychReseniView.as_view()), name='odevzdavatko_tabulka'),
|
path('temp/reseni/', org_required(views.TabulkaOdevzdanychReseniView.as_view()), name='odevzdavatko_tabulka'),
|
||||||
path('temp/reseni/<int:problem>/<int:resitel>/', org_required(views.ReseniProblemuView.as_view()), name='odevzdavatko_reseni_resitele_k_problemu'),
|
path('temp/reseni/<int:problem>/<int:resitel>/', org_required(views.ReseniProblemuView.as_view()), name='odevzdavatko_reseni_resitele_k_problemu'),
|
||||||
path('temp/reseni/<int:pk>', org_required(viewMethodSwitch(get=views.DetailReseniView.as_view(), post=views.HodnoceniReseniView.as_view())), name='odevzdavatko_detail_reseni'),
|
path('temp/reseni/<int:pk>', org_required(viewMethodSwitch(get=views.DetailReseniView.as_view(), post=views.hodnoceniReseniView)), name='odevzdavatko_detail_reseni'),
|
||||||
path('temp/reseni/all', org_required(views.SeznamReseniView.as_view())),
|
path('temp/reseni/all', org_required(views.SeznamReseniView.as_view())),
|
||||||
path('temp/reseni/akt', org_required(views.SeznamAktualnichReseniView.as_view())),
|
path('temp/reseni/akt', org_required(views.SeznamAktualnichReseniView.as_view())),
|
||||||
]
|
]
|
||||||
|
|
|
@ -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})
|
||||||
|
|
||||||
def get_success_url(self):
|
formset = f.OhodnoceniReseniFormSet(request.POST)
|
||||||
# Funkce to je jen proto, aby se dalo použít self.
|
if formset.is_valid():
|
||||||
return reverse('odevzdavatko_detail_reseni', kwargs={'pk': self.kwargs['pk']})
|
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 form_vaild(self, form):
|
return redirect(success_url)
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
# Přehled všech řešení kvůli debugování
|
# Přehled všech řešení kvůli debugování
|
||||||
|
|
Loading…
Reference in a new issue