Browse Source

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

export_seznamu_prednasek
Pavel "LEdoian" Turinsky 4 years ago
parent
commit
3e249aef5e
  1. 14
      seminar/views/odevzdavatko.py

14
seminar/views/odevzdavatko.py

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

Loading…
Cancel
Save