Přidán ProblemView
This commit is contained in:
		
							parent
							
								
									6e79237cef
								
							
						
					
					
						commit
						aca63f4e5e
					
				
					 1 changed files with 28 additions and 1 deletions
				
			
		|  | @ -141,7 +141,34 @@ class TreeNodeView(generic.DetailView): | ||||||
| 		context = super().get_context_data(**kwargs) | 		context = super().get_context_data(**kwargs) | ||||||
| 		context['tnldata'] = TNLData.from_treenode(self.object) | 		context['tnldata'] = TNLData.from_treenode(self.object) | ||||||
| 		return context | 		return context | ||||||
| 	 | 
 | ||||||
|  | class ProblemView(generic.DetailView): | ||||||
|  | 	model = s.Problem | ||||||
|  | 	# Zkopírujeme template_name od TreeNodeView, protože jsme prakticky jen trošku upravený TreeNodeView | ||||||
|  | 	template_name = TreeNodeView.template_name | ||||||
|  | 
 | ||||||
|  | 	def get_context_data(self, **kwargs): | ||||||
|  | 		context = super().get_context_data(**kwargs) | ||||||
|  | 		# Teď potřebujeme doplnit tnldata do kontextu. | ||||||
|  | 		# Ošklivý type switch, hezčí by bylo udělat to polymorfni. FIXME. | ||||||
|  | 		if False: | ||||||
|  | 			# Hezčí formátování zbytku :-P | ||||||
|  | 			pass | ||||||
|  | 		elif isinstance(self.object, s.Clanek) or  isinstance(self.object, s.Konfera): | ||||||
|  | 			# Tyhle Problémy mají ŘešeníNode | ||||||
|  | 			context['tnldata'] = TNLData.from_treenode(self.object.reseninode) | ||||||
|  | 		elif isinstance(self.object, s.Uloha): | ||||||
|  | 			# FIXME: Teď vždycky zobrazujeme i vzorák! Možná by bylo hezčí/lepší mít to stejně jako pro Téma: procházet jen dosažitelné z Ročníku / čísla / whatever | ||||||
|  | 			tnl_zadani = self.object.ulohazadaninode | ||||||
|  | 			tnl_vzorak = self.object.ulohavzoraknode | ||||||
|  | 			context['tnldata'] = TNLData.from_tnldata_list([tnl_zadani, tnl_vzorak]) | ||||||
|  | 		elif isinstance(self.object, s.Tema): | ||||||
|  | 			rocniknode = self.object.rocnik.rocniknode | ||||||
|  | 			context['tnldata'] = TNLData.filter_treenode(rocniknode, lambda x: isinstance(x, s.TemaVCisleNode)) | ||||||
|  | 		else: | ||||||
|  | 			raise ValueError("Obecný problém nejde zobrazit.") | ||||||
|  | 		return context | ||||||
|  | 
 | ||||||
| # TODO Co chceme vlastně zobrazovat na této stránce? Zatím je zde aktuální číslo, ale může tu být cokoli jiného... | # TODO Co chceme vlastně zobrazovat na této stránce? Zatím je zde aktuální číslo, ale může tu být cokoli jiného... | ||||||
| class AktualniZadaniView(TreeNodeView): | class AktualniZadaniView(TreeNodeView): | ||||||
| 	def get_object(self): | 	def get_object(self): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Pavel 'LEdoian' Turinsky
						Pavel 'LEdoian' Turinsky