Implementovaný ArchivTemataView
This commit is contained in:
		
							parent
							
								
									285020d7e0
								
							
						
					
					
						commit
						39dc2d8e32
					
				
					 2 changed files with 30 additions and 12 deletions
				
			
		|  | @ -7,17 +7,13 @@ | |||
|     {% endblock %}{% endblock%} | ||||
|   </h1> | ||||
| 
 | ||||
|   {% for tema in object_list %} | ||||
|   {% with tema.cislo_zadani.rocnik.rocnik as rocnik %} | ||||
|     {% ifchanged rocnik %} | ||||
|       {% if not forloop.first %}</ul>{% endif %} | ||||
|       <h2>{{ rocnik }}. ročník</h2> | ||||
|       <ul> | ||||
|     {% endifchanged %} | ||||
|         <li> | ||||
|           <a href="{{ tema.verejne_url }}">{{ tema.kod_v_rocniku }}: {{ tema.nazev }}</a> | ||||
|   {% endwith %} | ||||
|   {% for rocnik, temata in rocniky.items %} | ||||
|     <h2>Ročník {{ rocnik }}</h2> | ||||
|     <ul> | ||||
|     {% for tema in temata %} | ||||
|     <li><a href="{{ tema.verejne_utl }}"> {{ tema.kod_v_rocniku }}: {{ tema.nazev }} </a></li> | ||||
|     {% endfor %} | ||||
|     </ul> | ||||
|   {% endfor %} | ||||
|   </ul> | ||||
| 
 | ||||
| {% endblock content %} | ||||
|  |  | |||
|  | @ -27,6 +27,7 @@ import seminar.forms as f | |||
| from datetime import timedelta, date, datetime | ||||
| from django.utils import timezone | ||||
| from itertools import groupby | ||||
| from collections import OrderedDict | ||||
| import tempfile | ||||
| import subprocess | ||||
| import shutil | ||||
|  | @ -777,7 +778,28 @@ class CisloView(generic.DetailView): | |||
| class ArchivTemataView(generic.ListView): | ||||
| 	model = Problem | ||||
| 	template_name = 'seminar/archiv/temata.html' | ||||
| 	queryset = Tema.objects.filter(stav=Problem.STAV_ZADANY).select_related('cislo_zadani__rocnik').order_by('-cislo_zadani__rocnik__rocnik', 'kod') | ||||
| 	queryset = Tema.objects.filter(stav=Problem.STAV_ZADANY).select_related('rocnik').order_by('-rocnik', 'kod') | ||||
| 
 | ||||
| 	def get_context_data(self, *args, **kwargs): | ||||
| 		ctx = super().get_context_data(*args, **kwargs) | ||||
| 		# Najdeme, jaké ročníky mají témata | ||||
| 		# TODO: Tohle by se rovnou mohlo tahat z databáze, ne? | ||||
| 		#       Navíc už asi nepotřebuji ten select_related, že? | ||||
| 		rocniky_set = set() | ||||
| 		for tema in ctx['object_list']: | ||||
| 			rocniky_set.add(tema.rocnik) | ||||
| 		rocniky = list(rocniky_set) | ||||
| 		rocniky.sort(key=lambda r: int(r.rocnik), reverse=True) | ||||
| 
 | ||||
| 		# Přiřadíme témátka k ročníkům | ||||
| 		# TODO: Asi taky jde udělat nějak elegantněji, ne? | ||||
| 		ctx['rocniky'] = OrderedDict() | ||||
| 		for rocnik in rocniky: | ||||
| 			ctx['rocniky'][rocnik] = [] | ||||
| 			for tema in ctx['object_list']: | ||||
| 				if tema.rocnik == rocnik: | ||||
| 					ctx['rocniky'][rocnik].append(tema) | ||||
| 		return ctx | ||||
| 
 | ||||
| ### Generovani vysledkovky | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Pavel 'LEdoian' Turinsky
						Pavel 'LEdoian' Turinsky