Opravil jsem initial věci, aby nepadaly?
This commit is contained in:
		
							parent
							
								
									ffaf7d5d59
								
							
						
					
					
						commit
						90fb41e862
					
				
					 1 changed files with 18 additions and 6 deletions
				
			
		|  | @ -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]) | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Pavel "LEdoian" Turinsky
						Pavel "LEdoian" Turinsky