Browse Source

Implementováno zadávání bodů

export_seznamu_prednasek
Pavel "LEdoian" Turinsky 4 years ago
parent
commit
631bcd5bdb
  1. 2
      seminar/urls.py
  2. 38
      seminar/views/odevzdavatko.py

2
seminar/urls.py

@ -169,7 +169,7 @@ urlpatterns = [
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: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/akt', org_required(views.SeznamAktualnichReseniView.as_view())),
]

38
seminar/views/odevzdavatko.py

@ -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í

Loading…
Cancel
Save