From ffaf7d5d5946e4597f4bb0e821ff727151186466 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 2 Mar 2021 23:15:15 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Odevzd=C3=A1v=C3=A1tko:=20ve=20t=C5=99?= =?UTF-8?q?=C3=ADd=C4=9B=20nem=C3=A1=20b=C3=BDt=20k=C3=B3d,=20jinak=20to?= =?UTF-8?q?=20rozb=C3=ADj=C3=AD=20testdata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/forms.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/seminar/forms.py b/seminar/forms.py index 39714fae..800b8e35 100644 --- a/seminar/forms.py +++ b/seminar/forms.py @@ -382,11 +382,15 @@ class OdevzdavatkoTabulkaFiltrForm(forms.Form): return result + def __init__(self, *args, **kwargs): + 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() + # NOTE: Initial definuji pro jednotlivé fieldy, aby to bylo tady a nebylo potřeba to řešit ve views... resitele = forms.ChoiceField(choices=RESITELE_CHOICES, initial=RESITELE_RELEVANTNI) problemy = forms.ChoiceField(choices=PROBLEMY_CHOICES, initial=PROBLEMY_MOJE) - # choices jako parametr Select widgetu neumí brát callable, jen iterable, takže si pro jednoduchost můžu rovnou uložit výsledek sem... - terminy = gen_terminy() reseni_od = forms.DateField(input_formats=[DATE_FORMAT], widget=forms.Select(choices=terminy), initial=terminy[-2]) reseni_do = forms.DateField(input_formats=[DATE_FORMAT], widget=forms.Select(choices=terminy), initial=terminy[-1]) From 90fb41e8626dc302b0e3d6c7bd9efff94fd86268 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 9 Mar 2021 20:28:34 +0100 Subject: [PATCH 2/4] =?UTF-8?q?Opravil=20jsem=20initial=20v=C4=9Bci,=20aby?= =?UTF-8?q?=20nepadaly=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/forms.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/seminar/forms.py b/seminar/forms.py index 800b8e35..ba27c2df 100644 --- a/seminar/forms.py +++ b/seminar/forms.py @@ -347,7 +347,8 @@ class OdevzdavatkoTabulkaFiltrForm(forms.Form): # TODO: Typy problémů (problémy, úlohy, ostatní, všechny)? Jen některá řešení (obodovaná/neobodovaná, víc řešitelů, ...)? - def gen_terminy(): + @classmethod + def gen_terminy(cls): import datetime from time import strftime @@ -382,15 +383,26 @@ class OdevzdavatkoTabulkaFiltrForm(forms.Form): return result + @classmethod + def gen_initial(cls): + terminy = cls.gen_terminy() + initial = { + 'resitele': cls.RESITELE_RELEVANTNI, + 'problemy': cls.PROBLEMY_MOJE, + 'reseni_od': terminy[-2], + 'reseni_do': terminy[-1], + } + return initial + def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) + super().__init__(initial=self.gen_initial(), *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() # NOTE: Initial definuji pro jednotlivé fieldy, aby to bylo tady a nebylo potřeba to řešit ve views... - resitele = forms.ChoiceField(choices=RESITELE_CHOICES, initial=RESITELE_RELEVANTNI) - problemy = forms.ChoiceField(choices=PROBLEMY_CHOICES, initial=PROBLEMY_MOJE) + resitele = forms.ChoiceField(choices=RESITELE_CHOICES) + problemy = forms.ChoiceField(choices=PROBLEMY_CHOICES) - reseni_od = forms.DateField(input_formats=[DATE_FORMAT], widget=forms.Select(choices=terminy), initial=terminy[-2]) - reseni_do = forms.DateField(input_formats=[DATE_FORMAT], widget=forms.Select(choices=terminy), initial=terminy[-1]) +# reseni_od = forms.DateField(input_formats=[DATE_FORMAT], widget=forms.Select(choices=self.terminy)) + reseni_do = forms.DateField(input_formats=[DATE_FORMAT]) From 75742b72645f9e4b2a0e903551848e1857a3d85e Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 9 Mar 2021 20:38:47 +0100 Subject: [PATCH 3/4] s/FormFiltr/FiltrForm --- seminar/views/odevzdavatko.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/seminar/views/odevzdavatko.py b/seminar/views/odevzdavatko.py index d1cedb1b..14305b10 100644 --- a/seminar/views/odevzdavatko.py +++ b/seminar/views/odevzdavatko.py @@ -57,10 +57,10 @@ class TabulkaOdevzdanychReseniView(ListView): reseni_od = fcd["reseni_od"] reseni_do = fcd["reseni_do"] else: - resitele = FiltrForm.get_initial_for_field(FormFiltr.resitele, "resitele") - problemy = FiltrForm.get_initial_for_field(FormFiltr.problemy, "problemy") - resitele_od = FiltrForm.get_initial_for_field(FormFiltr.resitele_od, "resitele_od") - resitele_do = FiltrForm.get_initial_for_field(FormFiltr.resitele_do, "resitele_do") + 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") # Filtrujeme! From 4f04efd51908f939630918f4737f96cd3392a1ab Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 9 Mar 2021 21:33:53 +0100 Subject: [PATCH 4/4] =?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!