From 4f04efd51908f939630918f4737f96cd3392a1ab Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 9 Mar 2021 21:33:53 +0100 Subject: [PATCH] =?UTF-8?q?P=C3=A1r=20fix=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Initial nemá dostat lidské řetězce - Zahozeno get_initial_for_field --- seminar/forms.py | 12 +++++++++--- seminar/views/odevzdavatko.py | 9 +++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/seminar/forms.py b/seminar/forms.py index ba27c2df..5fbd54a3 100644 --- a/seminar/forms.py +++ b/seminar/forms.py @@ -389,13 +389,17 @@ class OdevzdavatkoTabulkaFiltrForm(forms.Form): initial = { 'resitele': cls.RESITELE_RELEVANTNI, 'problemy': cls.PROBLEMY_MOJE, - 'reseni_od': terminy[-2], - 'reseni_do': terminy[-1], + 'reseni_od': terminy[-2][0], + 'reseni_do': terminy[-1][0], } return initial def __init__(self, *args, **kwargs): - super().__init__(initial=self.gen_initial(), *args, **kwargs) + if 'initial' not in kwargs: + super().__init__(initial=self.gen_initial(), *args, **kwargs) + else: + super().__init__(*args, **kwargs) + # choices jako parametr Select widgetu neumí brát callable, jen iterable, takže si pro jednoduchost můžu rovnou uložit výsledek sem... # A "sem" znamená do libovolné metody, protože jinak se jedná o kód, který django spustí při inicializaci a protože potřebujeme databázi, tak by spadnul při vyrábění testdat... self.terminy = self.gen_terminy() @@ -405,4 +409,6 @@ class OdevzdavatkoTabulkaFiltrForm(forms.Form): problemy = forms.ChoiceField(choices=PROBLEMY_CHOICES) # reseni_od = forms.DateField(input_formats=[DATE_FORMAT], widget=forms.Select(choices=self.terminy)) +# reseni_do = forms.DateField(input_formats=[DATE_FORMAT], widget=forms.Select(choices=self.terminy)) + reseni_od = forms.DateField(input_formats=[DATE_FORMAT]) reseni_do = forms.DateField(input_formats=[DATE_FORMAT]) diff --git a/seminar/views/odevzdavatko.py b/seminar/views/odevzdavatko.py index 14305b10..7cc95d77 100644 --- a/seminar/views/odevzdavatko.py +++ b/seminar/views/odevzdavatko.py @@ -57,10 +57,11 @@ class TabulkaOdevzdanychReseniView(ListView): reseni_od = fcd["reseni_od"] reseni_do = fcd["reseni_do"] else: - resitele = FiltrForm.get_initial_for_field(FiltrForm.resitele, "resitele") - problemy = FiltrForm.get_initial_for_field(FiltrForm.problemy, "problemy") - resitele_od = FiltrForm.get_initial_for_field(FiltrForm.resitele_od, "resitele_od") - resitele_do = FiltrForm.get_initial_for_field(FiltrForm.resitele_do, "resitele_do") + initial = FiltrForm.gen_initial() + resitele = initial['resitele'] + problemy = initial['problemy'] + reseni_od = initial['reseni_od'] + reseni_do = initial['reseni_do'] # Filtrujeme!