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%}
|
{% endblock %}{% endblock%}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
{% for tema in object_list %}
|
{% for rocnik, temata in rocniky.items %}
|
||||||
{% with tema.cislo_zadani.rocnik.rocnik as rocnik %}
|
<h2>Ročník {{ rocnik }}</h2>
|
||||||
{% ifchanged rocnik %}
|
|
||||||
{% if not forloop.first %}</ul>{% endif %}
|
|
||||||
<h2>{{ rocnik }}. ročník</h2>
|
|
||||||
<ul>
|
<ul>
|
||||||
{% endifchanged %}
|
{% for tema in temata %}
|
||||||
<li>
|
<li><a href="{{ tema.verejne_utl }}"> {{ tema.kod_v_rocniku }}: {{ tema.nazev }} </a></li>
|
||||||
<a href="{{ tema.verejne_url }}">{{ tema.kod_v_rocniku }}: {{ tema.nazev }}</a>
|
|
||||||
{% endwith %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import seminar.forms as f
|
||||||
from datetime import timedelta, date, datetime
|
from datetime import timedelta, date, datetime
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
from collections import OrderedDict
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -777,7 +778,28 @@ class CisloView(generic.DetailView):
|
||||||
class ArchivTemataView(generic.ListView):
|
class ArchivTemataView(generic.ListView):
|
||||||
model = Problem
|
model = Problem
|
||||||
template_name = 'seminar/archiv/temata.html'
|
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
|
### Generovani vysledkovky
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue