From 653a564bfdc34e0774d790d71c6867595932b475 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 6 Apr 2021 20:39:18 +0200 Subject: [PATCH] =?UTF-8?q?Odevzd=C3=A1v=C3=A1tko:=20pl=C3=A1=C4=8D=20v=20?= =?UTF-8?q?koment=C3=A1=C5=99=C3=ADch=20nad=20Django=20templates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/views/odevzdavatko.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/seminar/views/odevzdavatko.py b/seminar/views/odevzdavatko.py index 4a58be05..3aa7e469 100644 --- a/seminar/views/odevzdavatko.py +++ b/seminar/views/odevzdavatko.py @@ -173,7 +173,9 @@ class ReseniProblemuView(MultipleObjectTemplateResponseMixin, MultipleObjectMixi def get_context_data(self, *args, **kwargs): ctx = super().get_context_data(*args, **kwargs) - # FIXME: Lepší by bylo předat groupby do template. + # XXX: Předat groupby do template nejde: https://stackoverflow.com/questions/6906593/itertools-groupby-in-a-django-template + # Django má {% regroup %}, ale ten potřebuje, aby klíč byl atribut položky: https://docs.djangoproject.com/en/3.2/ref/templates/builtins/#regroup + # Takže rozbalíme groupby do slovníku klíč → seznam sami (dictionary comphrehension) ctx['reseni_podle_deadlinu'] = {k: list(v) for k,v in groupby(ctx['object_list'], lambda r: deadline(r.cas_doruceni))} return ctx