Odevzdávatko: nezobrazovat seznam jednoho řešení

This commit is contained in:
Pavel "LEdoian" Turinsky 2021-01-19 21:18:48 +01:00
parent 658f2a53c6
commit 3e249aef5e

View file

@ -1,5 +1,9 @@
from django.views.generic import ListView, DetailView, FormView
from django.views.generic.list import MultipleObjectTemplateResponseMixin,MultipleObjectMixin
from django.views.generic.base import View
from django.views.generic.detail import SingleObjectMixin
from django.shortcuts import redirect
from django.urls import reverse
from dataclasses import dataclass
import datetime
@ -87,7 +91,8 @@ class TabulkaOdevzdanychReseniView(ListView):
return ctx
class ReseniProblemuView(ListView):
# Velmi silně inspirováno zdrojáky, FIXME: Nedá se to udělat smysluplněji?
class ReseniProblemuView(MultipleObjectTemplateResponseMixin, MultipleObjectMixin, View):
model = m.Reseni
template_name = 'seminar/odevzdavatko/seznam.html'
@ -108,6 +113,13 @@ class ReseniProblemuView(ListView):
)
return qs
def get(self, request, *args, **kwargs):
self.object_list = self.get_queryset()
if self.object_list.count() == 1:
jedine_reseni = self.object_list.first()
return redirect(reverse("odevzdavatko_detail_reseni", kwargs={"pk": jedine_reseni.id}))
context = self.get_context_data()
return self.render_to_response(context)
# Kontext automaticky?
## XXX: https://docs.djangoproject.com/en/3.1/topics/class-based-views/mixins/#avoid-anything-more-complex