current year first, sort latest to oldes withing year

This commit is contained in:
j 2024-01-26 12:52:26 +01:00
parent 2d91dfcacb
commit 641097e2d3
2 changed files with 26 additions and 12 deletions

View file

@ -83,7 +83,21 @@ def archive(request, year=None, month=None, day=None, week=None):
week = int(date.strftime('%W'))
year = int(year)
archive_week = archive.filter(year=year, week=week).order_by('published')
years = {}
context['weeks'] = get_weeks(archive)
years["2024"] = []
for week in get_weeks(archive):
print(week)
if week["year"] not in years:
years[week["year"]] = []
years[week["year"]].append(week)
context['years'] = []
for year in reversed(sorted(years)):
context['years'].append({
'year': year,
'weeks': years[year]
})
context['this_week'] = date.strftime('%Y-%m-%d')
context['this_year'] = date.strftime('%Y')
extra = models.Week.objects.filter(monday=context['this_week']).first()

View file

@ -18,13 +18,11 @@
</div>
{% if weeks %}
<div class="weeks">
{% for year in years %}
<div>
{% for week in weeks %}
{% ifchanged week.year %}
</div>
<h1>{{ week.year }}</h1>
<div class="year-details-{{ week.year }}" {% if week.year != this_year %} style="display: none"{% endif %}>
{% endifchanged %}
<h1>{{ year.year }}</h1>
<div class="year-details-{{ year.year }}">
{% for week in year.weeks %}
{% if week.date == this_week %}
<b>{{ week.title }}</b><br>
{% else %}
@ -32,6 +30,8 @@
{% endif %}
{% endfor %}
</div>
</div>
{% endfor %}
<script>
document.querySelectorAll('.weeks h1').forEach(h1 => {
h1.addEventListener('click', event => {