From 641097e2d36e333bcc7436d0fb74776fc681bc69 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 26 Jan 2024 12:52:26 +0100 Subject: [PATCH] current year first, sort latest to oldes withing year --- app/item/views.py | 14 ++++++++++++++ app/templates/archive.html | 24 ++++++++++++------------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/item/views.py b/app/item/views.py index 77ccbc2..fb85cdb 100644 --- a/app/item/views.py +++ b/app/item/views.py @@ -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() diff --git a/app/templates/archive.html b/app/templates/archive.html index cfca179..cdb07bc 100644 --- a/app/templates/archive.html +++ b/app/templates/archive.html @@ -18,20 +18,20 @@ {% if weeks %}
-
- {% for week in weeks %} - {% ifchanged week.year %} + {% for year in years %} +
+

{{ year.year }}

+
+ {% for week in year.weeks %} + {% if week.date == this_week %} + {{ week.title }}
+ {% else %} + {{ week.title }}
+ {% endif %} + {% endfor %}
-

{{ week.year }}

- {% endfor %} -