Merge branch 'data_migrations' of gimli.ms.mff.cuni.cz:/akce/mam/git/mamweb into data_migrations
This commit is contained in:
		
						commit
						8f136682d4
					
				
					 3 changed files with 57 additions and 17 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ů, ...)? | 	# 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 | 		import datetime | ||||||
| 		from time import strftime | 		from time import strftime | ||||||
| 		 | 		 | ||||||
|  | @ -390,11 +391,44 @@ class OdevzdavatkoTabulkaFiltrForm(forms.Form): | ||||||
| 
 | 
 | ||||||
| 		return result | 		return result | ||||||
| 
 | 
 | ||||||
|  | 	@classmethod | ||||||
|  | 	def gen_terminy_safe(cls): | ||||||
|  | 		"Při prvotních migracích / nasazeních webu neexistuje nastavení, takže to hodí výjimku, kterou musíme požrat..." | ||||||
|  | 		try: | ||||||
|  | 			return cls.gen_terminy() | ||||||
|  | 		except NotImplementedError: | ||||||
|  | 			return [ | ||||||
|  | 				('1970-01-01', "Je to rozbitý"), | ||||||
|  | 				('2012-12-12', "Svět skončil v roce 2012") | ||||||
|  | 				] | ||||||
|  | 
 | ||||||
|  | 	@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): | ||||||
|  | 		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() | ||||||
|  | 		self.fields['reseni_od'].widget = forms.Select(choices=self.gen_terminy_safe()) | ||||||
|  | 		self.fields['reseni_od'].initial = self.terminy[-2] | ||||||
|  | 		self.fields['reseni_do'].widget = forms.Select(choices=self.gen_terminy_safe()) | ||||||
|  | 		self.fields['reseni_do'].initial = self.terminy[-1] | ||||||
|  | 
 | ||||||
| 	# NOTE: Initial definuji pro jednotlivé fieldy, aby to bylo tady a nebylo potřeba to řešit ve views... | 	# 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) | 	resitele = forms.ChoiceField(choices=RESITELE_CHOICES) | ||||||
| 	problemy = forms.ChoiceField(choices=PROBLEMY_CHOICES, initial=PROBLEMY_MOJE) | 	problemy = forms.ChoiceField(choices=PROBLEMY_CHOICES) | ||||||
| 	 | 	 | ||||||
| 	# choices jako parametr Select widgetu neumí brát callable, jen iterable, takže si pro jednoduchost můžu rovnou uložit výsledek sem... | 	reseni_od = forms.DateField(input_formats=[DATE_FORMAT]) | ||||||
| 	terminy = gen_terminy() | 	reseni_do = forms.DateField(input_formats=[DATE_FORMAT]) | ||||||
| 	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]) |  | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| <h2><strong>Informace, komunikace</strong></h2> | <h2><strong>Informace, komunikace</strong></h2> | ||||||
| 
 | 
 | ||||||
| <ul> | <ul> | ||||||
| 	<li><strong><a href="https://wiki.mam.bezva.org/">wiki</a> </strong>obsahuje různé návody a know-how</li> | 	<li><strong><a href="/wiki/">wiki</a> </strong>obsahuje různé návody a know-how</li> | ||||||
| 	<li><strong><a href="https://riot.im/app/#/room/#orgovna:dolujeme.eu">Riot</a> </strong>chatování s dalšími orgy</li> | 	<li><strong><a href="https://riot.im/app/#/room/#orgovna:dolujeme.eu">Riot</a> </strong>chatování s dalšími orgy</li> | ||||||
| 	<li><strong>Kanboard </strong>správa TODO | 	<li><strong>Kanboard </strong>správa TODO | ||||||
| 	<ul> | 	<ul> | ||||||
|  |  | ||||||
|  | @ -57,17 +57,19 @@ class TabulkaOdevzdanychReseniView(ListView): | ||||||
| 			reseni_od = fcd["reseni_od"] | 			reseni_od = fcd["reseni_od"] | ||||||
| 			reseni_do = fcd["reseni_do"] | 			reseni_do = fcd["reseni_do"] | ||||||
| 		else: | 		else: | ||||||
| 			resitele = FiltrForm.get_initial_for_field(FormFiltr.resitele, "resitele") | 			initial = FiltrForm.gen_initial() | ||||||
| 			problemy = FiltrForm.get_initial_for_field(FormFiltr.problemy, "problemy") | 			resitele = initial['resitele'] | ||||||
| 			resitele_od = FiltrForm.get_initial_for_field(FormFiltr.resitele_od, "resitele_od") | 			problemy = initial['problemy'] | ||||||
| 			resitele_do = FiltrForm.get_initial_for_field(FormFiltr.resitele_do, "resitele_do") | 			reseni_od = initial['reseni_od'][0] | ||||||
|  | 			reseni_do = initial['reseni_do'][0] | ||||||
| 			 | 			 | ||||||
| 
 | 
 | ||||||
| 		# Filtrujeme! | 		# Filtrujeme! | ||||||
| 		aktualni_rocnik = m.Nastaveni.get_solo().aktualni_rocnik	# .get_solo() vrátí tu jedinou instanci | 		aktualni_rocnik = m.Nastaveni.get_solo().aktualni_rocnik	# .get_solo() vrátí tu jedinou instanci | ||||||
|  | 		self.chteni_resitele = resitele	# Zapamatování pro get_context_data | ||||||
| 		if resitele == FiltrForm.RESITELE_RELEVANTNI: | 		if resitele == FiltrForm.RESITELE_RELEVANTNI: | ||||||
| 			logger.warning("Někdo chtěl v tabulce jen relevantní řešitele a měl smůlu :-(") | 			# TODO: Zkontrolovat, že resi_v_rocniku vrací QuerySet (jinak asi bude žrát spoustu zdrojů zbytečně) | ||||||
| 			resitele = FiltrForm.RESITELE_LETOSNI # Fall-through | 			self.resitele = resi_v_rocniku(aktualni_rocnik)	# Prvotní sada, pokud nebude mít body, odstraní se v get_context_data | ||||||
| 		elif resitele == FiltrForm.RESITELE_LETOSNI: | 		elif resitele == FiltrForm.RESITELE_LETOSNI: | ||||||
| 			self.resitele = resi_v_rocniku(aktualni_rocnik) | 			self.resitele = resi_v_rocniku(aktualni_rocnik) | ||||||
| 
 | 
 | ||||||
|  | @ -118,16 +120,20 @@ class TabulkaOdevzdanychReseniView(ListView): | ||||||
| 				pridej_reseni(hodnoceni.problem, resitel, hodnoceni.body, hodnoceni.reseni.cas_doruceni) | 				pridej_reseni(hodnoceni.problem, resitel, hodnoceni.body, hodnoceni.reseni.cas_doruceni) | ||||||
| 
 | 
 | ||||||
| 		hodnoty = [] | 		hodnoty = [] | ||||||
|  | 		resitele_do_tabulky = [] | ||||||
| 		for resitel in self.resitele: | 		for resitel in self.resitele: | ||||||
|  | 			dostal_body = False | ||||||
| 			resiteluv_radek = [] | 			resiteluv_radek = [] | ||||||
| 			for problem in self.problemy: | 			for problem in self.problemy: | ||||||
| 				if problem in tabulka and resitel in tabulka[problem]: | 				if problem in tabulka and resitel in tabulka[problem]: | ||||||
| 					resiteluv_radek.append(tabulka[problem][resitel]) | 					resiteluv_radek.append(tabulka[problem][resitel]) | ||||||
|  | 					dostal_body = True | ||||||
| 				else: | 				else: | ||||||
| 					resiteluv_radek.append(None) | 					resiteluv_radek.append(None) | ||||||
| 			hodnoty.append(resiteluv_radek) | 			if self.chteni_resitele != FiltrForm.RESITELE_RELEVANTNI or dostal_body: | ||||||
| 		ctx['radky'] = list(zip(self.resitele, hodnoty)) | 				hodnoty.append(resiteluv_radek) | ||||||
| 
 | 				resitele_do_tabulky.append(resitel) | ||||||
|  | 		ctx['radky'] = list(zip(resitele_do_tabulky, hodnoty)) | ||||||
| 		ctx['filtr'] = FiltrForm(initial=self.request.GET) | 		ctx['filtr'] = FiltrForm(initial=self.request.GET) | ||||||
| 		# Pro použití hacku na automatické {{form.media}} v template: | 		# Pro použití hacku na automatické {{form.media}} v template: | ||||||
| 		ctx['form'] = ctx['filtr'] | 		ctx['form'] = ctx['filtr'] | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue